@@ -28,7 +28,7 @@ This option can also be set using the [command-line option](#command-line) `--pl
2828
2929 ```bash
3030 export CIBW_BUILD='cp37-*'
31- export CIBW_TEST_COMMAND='pytest . /tests'
31+ export CIBW_TEST_COMMAND='pytest {project} /tests'
3232 cibuildwheel --platform linux .
3333 ```
3434
@@ -1284,23 +1284,23 @@ Shell command to run tests after the build. The wheel will be installed
12841284automatically and available for import from the tests. If this variable is not
12851285set, your wheel will not be installed after building.
12861286
1287- By default, tests are executed from your project directory. When specifying
1288- ` test-command ` , you can optionally use the placeholders ` {package} ` and
1289- ` {project} ` to pass in the location of your test code :
1287+ To ensure the wheel is imported by your tests (instead of your source copy),
1288+ ** Tests are executed from a temporary directory ** , outside of your source
1289+ tree. To access your test code, you have a couple of options :
12901290
1291- - ` {package} ` is the path to the package being built - the ` package_dir `
1292- argument supplied to cibuildwheel on the command line.
1293- - ` {project} ` is an absolute path to the project root - the working directory
1294- where cibuildwheel was called .
1291+ - You can use the [ ` test-sources ` ] ( #test-sources ) setting to copy specific
1292+ files from your source tree into the temporary directory. When using
1293+ test-sources, use relative paths in your test command, as if they were
1294+ relative to the project root .
12951295
1296- Using ` {package} ` or ` {project} ` used to be required, but since cibuildwheel
1297- 3.0, tests are run from the project root by default. This means that you can
1298- use relative paths in your test command, and they will be relative to the
1299- project root.
1296+ - You can use the ` {package} ` or ` {project} ` placeholders in your
1297+ ` test-command ` to refer to the package being built or the project root,
1298+ respectively.
13001299
1301- Alternatively, you can use the [ ` test-sources ` ] ( #test-sources ) setting to
1302- create a temporary folder populated with a specific subset of project files to
1303- run your test suite.
1300+ - ` {package} ` is the path to the package being built - the ` package_dir `
1301+ argument supplied to cibuildwheel on the command line.
1302+ - ` {project} ` is an absolute path to the project root - the working
1303+ directory where cibuildwheel was called.
13041304
13051305On all platforms other than iOS, the command is run in a shell, so you can write things like ` cmd1 && cmd2 ` .
13061306
@@ -1318,18 +1318,18 @@ Platform-specific environment variables are also available:<br/>
13181318 ```toml
13191319 [tool.cibuildwheel]
13201320 # Run the package tests using `pytest`
1321- test-command = "pytest . /tests"
1321+ test-command = "pytest {project} /tests"
13221322
13231323 # Trigger an install of the package, but run nothing of note
13241324 test-command = "echo Wheel installed"
13251325
13261326 # Multiline example
13271327 test-command = [
1328- "pytest . /tests",
1329- "python . /test.py",
1328+ "pytest {project} /tests",
1329+ "python {project} /test.py",
13301330 ]
13311331
1332- # run tests on ios
1332+ # run tests on ios - when test-sources is set, use relative paths, not {project} or {package}
13331333 [tool.cibuildwheel.ios]
13341334 test-sources = ["tests"]
13351335 test-command = "python -m pytest ./tests"
@@ -1341,17 +1341,17 @@ Platform-specific environment variables are also available:<br/>
13411341
13421342 ```yaml
13431343 # Run the package tests using `pytest`
1344- CIBW_TEST_COMMAND: pytest . /tests
1344+ CIBW_TEST_COMMAND: pytest {project} /tests
13451345
13461346 # Trigger an install of the package, but run nothing of note
13471347 CIBW_TEST_COMMAND: "echo Wheel installed"
13481348
13491349 # Multi-line example - join with && on all platforms
13501350 CIBW_TEST_COMMAND: >
1351- pytest . /tests &&
1352- python . /test.py
1351+ pytest {project} /tests &&
1352+ python {project} /test.py
13531353
1354- # run tests on ios
1354+ # run tests on ios - when test-sources is set, use relative paths, not {project} or {package}
13551355 CIBW_TEST_SOURCES_IOS: tests
13561356 CIBW_TEST_COMMAND_IOS: python -m pytest ./tests
13571357 ```
0 commit comments