Skip to content

Commit 9381cbd

Browse files
committed
Convert the normal test invocation to pytest ./tests, not placeholder
1 parent 65a5afb commit 9381cbd

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

docs/configuration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
1717
```yaml
1818
env:
1919
CIBW_TEST_REQUIRES: pytest
20-
CIBW_TEST_COMMAND: "pytest {project}/tests"
20+
CIBW_TEST_COMMAND: "pytest ./tests"
2121
```
2222

2323
!!! tab "Azure Pipelines"
@@ -27,7 +27,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
2727
```yaml
2828
variables:
2929
CIBW_TEST_REQUIRES: pytest
30-
CIBW_TEST_COMMAND: "pytest {project}/tests"
30+
CIBW_TEST_COMMAND: "pytest ./tests"
3131
```
3232

3333
!!! tab "Travis CI"
@@ -38,7 +38,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
3838
env:
3939
global:
4040
- CIBW_TEST_REQUIRES=pytest
41-
- CIBW_TEST_COMMAND="pytest {project}/tests"
41+
- CIBW_TEST_COMMAND="pytest ./tests"
4242
```
4343

4444
!!! tab "AppVeyor"
@@ -61,7 +61,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
6161
job_name:
6262
environment:
6363
CIBW_TEST_REQUIRES: pytest
64-
CIBW_TEST_COMMAND: "pytest {project}/tests"
64+
CIBW_TEST_COMMAND: "pytest ./tests"
6565
```
6666

6767
!!! tab "Gitlab CI"
@@ -72,7 +72,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
7272
linux:
7373
variables:
7474
CIBW_TEST_REQUIRES: pytest
75-
CIBW_TEST_COMMAND: "pytest {project}/tests"
75+
CIBW_TEST_COMMAND: "pytest ./tests"
7676
```
7777

7878
!!! tab "Cirrus CI"
@@ -82,7 +82,7 @@ cibuildwheel to run tests, add the following YAML to your CI config file:
8282
```yaml
8383
env:
8484
CIBW_TEST_REQUIRES: pytest
85-
CIBW_TEST_COMMAND: "pytest {project}/tests"
85+
CIBW_TEST_COMMAND: "pytest ./tests"
8686
```
8787

8888
## Configuration file {: #configuration-file}
@@ -101,7 +101,7 @@ The example above using environment variables could have been written like this:
101101
```toml
102102
[tool.cibuildwheel]
103103
test-requires = "pytest"
104-
test-command = "pytest {project}/tests"
104+
test-command = "pytest ./tests"
105105
```
106106

107107
The complete set of defaults for the current version of cibuildwheel are shown below:

docs/options.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This option can also be set using the [command-line option](#command-line) `--pl
2626

2727
```bash
2828
export CIBW_BUILD='cp37-*'
29-
export CIBW_TEST_COMMAND='pytest {package}/tests'
29+
export CIBW_TEST_COMMAND='pytest ./tests'
3030
cibuildwheel --platform linux .
3131
```
3232

@@ -1223,13 +1223,18 @@ automatically and available for import from the tests. If this variable is not
12231223
set, your wheel will not be installed after building.
12241224

12251225
By default, tests are executed from your project directory. When specifying
1226-
`CIBW_TEST_COMMAND`, you can use the placeholders `{project}` and `{package}` to
1227-
pass in the location of your test code:
1226+
`CIBW_TEST_COMMAND`, you can optionally use the placeholders `{package}` and
1227+
`{project}` to pass in the location of your test code:
12281228

1229-
- `{project}` is an absolute path to the project root - the working directory
1230-
where cibuildwheel was called.
12311229
- `{package}` is the path to the package being built - the `package_dir`
12321230
argument supplied to cibuildwheel on the command line.
1231+
- `{project}` is an absolute path to the project root - the working directory
1232+
where cibuildwheel was called.
1233+
1234+
Using `{package}` or `{project}` used to be required, but since cibuildwheel
1235+
3.0, tests are run from the project root by default. This means that you can
1236+
use relative paths in your test command, and they will be relative to the
1237+
project root.
12331238

12341239
Alternatively, you can use the [`CIBW_TEST_SOURCES`](#test-sources) setting to
12351240
create a temporary folder populated with a specific subset of project files to
@@ -1248,44 +1253,36 @@ Platform-specific environment variables are also available:<br/>
12481253

12491254
```yaml
12501255
# Run the package tests using `pytest`
1251-
CIBW_TEST_COMMAND: pytest {package}/tests
1256+
CIBW_TEST_COMMAND: pytest ./tests
12521257

12531258
# Trigger an install of the package, but run nothing of note
12541259
CIBW_TEST_COMMAND: "echo Wheel installed"
12551260

12561261
# Multi-line example - join with && on all platforms
12571262
CIBW_TEST_COMMAND: >
1258-
pytest {package}/tests &&
1259-
python {package}/test.py
1263+
pytest ./tests &&
1264+
python ./test.py
12601265
```
12611266

12621267
!!! tab examples "pyproject.toml"
12631268

12641269
```toml
12651270
[tool.cibuildwheel]
12661271
# Run the package tests using `pytest`
1267-
test-command = "pytest {package}/tests"
1272+
test-command = "pytest ./tests"
12681273

12691274
# Trigger an install of the package, but run nothing of note
12701275
test-command = "echo Wheel installed"
12711276

12721277
# Multiline example
12731278
test-command = [
1274-
"pytest {package}/tests",
1275-
"python {package}/test.py",
1279+
"pytest ./tests",
1280+
"python ./test.py",
12761281
]
12771282
```
12781283

12791284
In configuration files, you can use an array, and the items will be joined with `&&`.
12801285

1281-
!!! note
1282-
1283-
It isn't recommended to `cd` to your project directory before running tests,
1284-
because Python might resolve `import yourpackage` relative to the working dir,
1285-
and we want to test the wheel you just built. However, if you're sure that's not
1286-
an issue for you and your workflow requires it, on Windows you should do `cd /d`,
1287-
because the CWD and project dir might be on different drives.
1288-
12891286
### `CIBW_BEFORE_TEST` {: #before-test}
12901287
> Execute a shell command before testing each wheel
12911288

test/test_abi_variants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_abi_none(tmp_path, capfd):
180180
project_dir,
181181
add_env={
182182
"CIBW_TEST_REQUIRES": "pytest",
183-
"CIBW_TEST_COMMAND": f"{utils.invoke_pytest()} {{project}}/test",
183+
"CIBW_TEST_COMMAND": f"{utils.invoke_pytest()} ./test",
184184
# limit the number of builds for test performance reasons
185185
"CIBW_BUILD": "cp38-* cp{}{}-* cp313t-* pp310-*".format(*utils.SINGLE_PYTHON_VERSION),
186186
},

test/test_before_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def test(tmp_path, build_frontend_env):
6262
"CIBW_TEST_REQUIRES": "pytest",
6363
# the 'false ||' bit is to ensure this command runs in a shell on
6464
# mac/linux.
65-
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test",
66-
"CIBW_TEST_COMMAND_WINDOWS": "pytest {project}/test",
65+
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} ./test",
66+
"CIBW_TEST_COMMAND_WINDOWS": "pytest ./test",
6767
**build_frontend_env,
6868
},
6969
)

test/test_emulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test(tmp_path, request):
3232
project_dir,
3333
add_env={
3434
"CIBW_TEST_REQUIRES": "pytest",
35-
"CIBW_TEST_COMMAND": "pytest {project}/test",
35+
"CIBW_TEST_COMMAND": "pytest ./test",
3636
"CIBW_ARCHS": archs,
3737
},
3838
)

test/test_testing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def test(tmp_path):
8080
"CIBW_TEST_REQUIRES": "pytest",
8181
# the 'false ||' bit is to ensure this command runs in a shell on
8282
# mac/linux.
83-
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test",
84-
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest {project}/test",
83+
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} ./test",
84+
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest ./test",
8585
},
8686
)
8787

@@ -101,8 +101,8 @@ def test_extras_require(tmp_path):
101101
"CIBW_TEST_EXTRAS": "test",
102102
# the 'false ||' bit is to ensure this command runs in a shell on
103103
# mac/linux.
104-
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test",
105-
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest {project}/test",
104+
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} ./test",
105+
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest ./test",
106106
},
107107
single_python=True,
108108
)
@@ -133,8 +133,8 @@ def test_dependency_groups(tmp_path):
133133
"CIBW_TEST_GROUPS": "dev",
134134
# the 'false ||' bit is to ensure this command runs in a shell on
135135
# mac/linux.
136-
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test",
137-
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest {project}/test",
136+
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} ./test",
137+
"CIBW_TEST_COMMAND_WINDOWS": "COLOR 00 || pytest ./test",
138138
},
139139
single_python=True,
140140
)
@@ -166,7 +166,7 @@ def test_failing_test(tmp_path):
166166
output_dir=output_dir,
167167
add_env={
168168
"CIBW_TEST_REQUIRES": "pytest",
169-
"CIBW_TEST_COMMAND": f"{utils.invoke_pytest()} {{project}}/test",
169+
"CIBW_TEST_COMMAND": f"{utils.invoke_pytest()} ./test",
170170
# CPython 3.8 when running on macOS arm64 is unusual. The build
171171
# always runs in x86_64, so the arm64 tests are not run. See
172172
# #1169 for reasons why. That means the build succeeds, which

0 commit comments

Comments
 (0)