Skip to content

Commit

Permalink
chore(tests): do not use hard-coded paths in test_before_test
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed May 25, 2024
1 parent ba8be0d commit a0166d4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/test_before_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_version(self):
# assert that the Python version as written to pythonversion_bt.txt in the CIBW_BEFORE_TEST step
# is the same one as is currently running.
# because of use symlinks in MacOS run this test is also need
version_file = 'c:\\pythonversion_bt.txt' if sys.platform == 'win32' else '/tmp/pythonversion_bt.txt'
version_file = os.environ["VERSION_FILE"]
with open(version_file) as f:
stored_version = f.read()
print('stored_version', stored_version)
Expand All @@ -23,7 +23,7 @@ def test_version(self):
def test_prefix(self):
# check that the prefix also was written
prefix_file = 'c:\\pythonprefix_bt.txt' if sys.platform == 'win32' else '/tmp/pythonprefix_bt.txt'
prefix_file = os.environ["PREFIX_FILE"]
with open(prefix_file) as f:
stored_prefix = f.read()
print('stored_prefix', stored_prefix)
Expand All @@ -40,15 +40,23 @@ def test(tmp_path):
before_test_project.generate(project_dir)
test_project_dir = project_dir / "dependency"
test_projects.new_c_project().generate(test_project_dir)
if utils.platform == "linux":
version_file = "/tmp/pythonversion_bt.txt"
prefix_file = "/tmp/pythonprefix_bt.txt"
else:
version_file = str(tmp_path / "pythonversion_bt.txt")
prefix_file = str(tmp_path / "pythonprefix_bt.txt")

# build the wheels
actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
# write python version information to a temporary file, this is
# checked in setup.py
"CIBW_BEFORE_TEST": """python -c "import sys; open('/tmp/pythonversion_bt.txt', 'w').write(sys.version)" && python -c "import sys; open('/tmp/pythonprefix_bt.txt', 'w').write(sys.prefix)" && python -m pip install {project}/dependency""",
"CIBW_BEFORE_TEST_WINDOWS": """python -c "import sys; open('c:\\pythonversion_bt.txt', 'w').write(sys.version)" && python -c "import sys; open('c:\\pythonprefix_bt.txt', 'w').write(sys.prefix)" && python -m pip install {project}/dependency""",
"VERSION_FILE": version_file,
"PREFIX_FILE": prefix_file,
"CIBW_ENVIRONMENT_PASS_LINUX": "VERSION_FILE PREFIX_FILE",
"CIBW_BEFORE_TEST": """python -c "import os, sys; open(os.environ['VERSION_FILE'], 'w').write(sys.version)" && python -c "import os, sys; open(os.environ['PREFIX_FILE'], 'w').write(sys.prefix)" && python -m pip install {project}/dependency""",
"CIBW_TEST_REQUIRES": "pytest",
# the 'false ||' bit is to ensure this command runs in a shell on
# mac/linux.
Expand Down

0 comments on commit a0166d4

Please sign in to comment.