Skip to content

Commit a157a51

Browse files
committed
Use a unittest style test to support more test runners
1 parent c417dce commit a157a51

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# this file is copied to the testing cwd, to raise the below error message if
2-
# pytest is run from there
2+
# pytest/unittest is run from there.
33

4+
import unittest
45

5-
def test():
6-
assert False, (
7-
"cibuildwheel executes tests from a different working directory to "
8-
"your project. This ensures only your wheel is imported, preventing "
9-
"Python from accessing files that haven't been packaged into the "
10-
"wheel. Please specify a path to your tests when invoking pytest "
11-
"using the {project} placeholder, e.g. `pytest {project}` or "
12-
"`pytest {project}/tests`. cibuildwheel will replace {project} with "
13-
"the path to your project."
14-
)
6+
7+
class TestStringMethods(unittest.TestCase):
8+
def test_fail(self):
9+
self.fail(
10+
"cibuildwheel executes tests from a different working directory to "
11+
"your project. This ensures only your wheel is imported, preventing "
12+
"Python from accessing files that haven't been packaged into the "
13+
"wheel. Please specify a path to your tests when invoking pytest "
14+
"using the {project} placeholder, e.g. `pytest {project}` or "
15+
"`pytest {project}/tests`. cibuildwheel will replace {project} with "
16+
"the path to your project."
17+
)

test/test_testing.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ def test_failing_test(tmp_path):
154154
assert len(os.listdir(output_dir)) == 0
155155

156156

157-
def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str]):
157+
@pytest.mark.parametrize("test_runner", ["pytest", "unittest"])
158+
def test_bare_pytest_invocation(
159+
tmp_path: Path, capfd: pytest.CaptureFixture[str], test_runner: str
160+
):
158161
"""Check that if a user runs pytest in the the test cwd, it raises a helpful error"""
159162
project_dir = tmp_path / "project"
160163
output_dir = tmp_path / "output"
@@ -165,8 +168,10 @@ def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str
165168
project_dir,
166169
output_dir=output_dir,
167170
add_env={
168-
"CIBW_TEST_REQUIRES": "pytest",
169-
"CIBW_TEST_COMMAND": "python -m pytest",
171+
"CIBW_TEST_REQUIRES": "pytest" if test_runner == "pytest" else "",
172+
"CIBW_TEST_COMMAND": (
173+
"python -m pytest" if test_runner == "pytest" else "python -m unittest"
174+
),
170175
# Skip CPython 3.8 on macOS arm64, see comment above in
171176
# 'test_failing_test'
172177
"CIBW_SKIP": "cp38-macosx_arm64",
@@ -179,5 +184,5 @@ def test_bare_pytest_invocation(tmp_path: Path, capfd: pytest.CaptureFixture[str
179184

180185
assert (
181186
"Please specify a path to your tests when invoking pytest using the {project} placeholder"
182-
in captured.out
187+
in captured.out + captured.err
183188
)

0 commit comments

Comments
 (0)