Use a unittest style test to support more test runners

This commit is contained in:
Joe Rickerby
2022-12-05 19:52:09 +00:00
parent c417dce602
commit a157a51225
2 changed files with 23 additions and 15 deletions
+14 -11
View File
@@ -1,14 +1,17 @@
# this file is copied to the testing cwd, to raise the below error message if # this file is copied to the testing cwd, to raise the below error message if
# pytest is run from there # pytest/unittest is run from there.
import unittest
def test(): class TestStringMethods(unittest.TestCase):
assert False, ( def test_fail(self):
"cibuildwheel executes tests from a different working directory to " self.fail(
"your project. This ensures only your wheel is imported, preventing " "cibuildwheel executes tests from a different working directory to "
"Python from accessing files that haven't been packaged into the " "your project. This ensures only your wheel is imported, preventing "
"wheel. Please specify a path to your tests when invoking pytest " "Python from accessing files that haven't been packaged into the "
"using the {project} placeholder, e.g. `pytest {project}` or " "wheel. Please specify a path to your tests when invoking pytest "
"`pytest {project}/tests`. cibuildwheel will replace {project} with " "using the {project} placeholder, e.g. `pytest {project}` or "
"the path to your project." "`pytest {project}/tests`. cibuildwheel will replace {project} with "
) "the path to your project."
)
+9 -4
View File
@@ -154,7 +154,10 @@ def test_failing_test(tmp_path):
assert len(os.listdir(output_dir)) == 0 assert len(os.listdir(output_dir)) == 0
def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str]): @pytest.mark.parametrize("test_runner", ["pytest", "unittest"])
def test_bare_pytest_invocation(
tmp_path: Path, capfd: pytest.CaptureFixture[str], test_runner: str
):
"""Check that if a user runs pytest in the the test cwd, it raises a helpful error""" """Check that if a user runs pytest in the the test cwd, it raises a helpful error"""
project_dir = tmp_path / "project" project_dir = tmp_path / "project"
output_dir = tmp_path / "output" output_dir = tmp_path / "output"
@@ -165,8 +168,10 @@ def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str
project_dir, project_dir,
output_dir=output_dir, output_dir=output_dir,
add_env={ add_env={
"CIBW_TEST_REQUIRES": "pytest", "CIBW_TEST_REQUIRES": "pytest" if test_runner == "pytest" else "",
"CIBW_TEST_COMMAND": "python -m pytest", "CIBW_TEST_COMMAND": (
"python -m pytest" if test_runner == "pytest" else "python -m unittest"
),
# Skip CPython 3.8 on macOS arm64, see comment above in # Skip CPython 3.8 on macOS arm64, see comment above in
# 'test_failing_test' # 'test_failing_test'
"CIBW_SKIP": "cp38-macosx_arm64", "CIBW_SKIP": "cp38-macosx_arm64",
@@ -179,5 +184,5 @@ def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str
assert ( assert (
"Please specify a path to your tests when invoking pytest using the {project} placeholder" "Please specify a path to your tests when invoking pytest using the {project} placeholder"
in captured.out in captured.out + captured.err
) )