Revert to running tests from from a temp dir when test-sources is unset (#2420)
* Revert to running tests from from a temp dir when test-sources is unset
* Fix placeholders error message, add test for it
* Add back {project} placeholders to CIBW_TEST_COMMAND in tests & docs
* Update test/test_before_test.py
---------
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
co-authored by
Henry Schreiner
parent
7298563b25
commit
6379772957
+23
-23
@@ -28,7 +28,7 @@ This option can also be set using the [command-line option](#command-line) `--pl
|
||||
|
||||
```bash
|
||||
export CIBW_BUILD='cp37-*'
|
||||
export CIBW_TEST_COMMAND='pytest ./tests'
|
||||
export CIBW_TEST_COMMAND='pytest {project}/tests'
|
||||
cibuildwheel --platform linux .
|
||||
```
|
||||
|
||||
@@ -1284,23 +1284,23 @@ Shell command to run tests after the build. The wheel will be installed
|
||||
automatically and available for import from the tests. If this variable is not
|
||||
set, your wheel will not be installed after building.
|
||||
|
||||
By default, tests are executed from your project directory. When specifying
|
||||
`test-command`, you can optionally use the placeholders `{package}` and
|
||||
`{project}` to pass in the location of your test code:
|
||||
To ensure the wheel is imported by your tests (instead of your source copy),
|
||||
**Tests are executed from a temporary directory**, outside of your source
|
||||
tree. To access your test code, you have a couple of options:
|
||||
|
||||
- `{package}` is the path to the package being built - the `package_dir`
|
||||
argument supplied to cibuildwheel on the command line.
|
||||
- `{project}` is an absolute path to the project root - the working directory
|
||||
where cibuildwheel was called.
|
||||
- You can use the [`test-sources`](#test-sources) setting to copy specific
|
||||
files from your source tree into the temporary directory. When using
|
||||
test-sources, use relative paths in your test command, as if they were
|
||||
relative to the project root.
|
||||
|
||||
Using `{package}` or `{project}` used to be required, but since cibuildwheel
|
||||
3.0, tests are run from the project root by default. This means that you can
|
||||
use relative paths in your test command, and they will be relative to the
|
||||
project root.
|
||||
- You can use the `{package}` or `{project}` placeholders in your
|
||||
`test-command` to refer to the package being built or the project root,
|
||||
respectively.
|
||||
|
||||
Alternatively, you can use the [`test-sources`](#test-sources) setting to
|
||||
create a temporary folder populated with a specific subset of project files to
|
||||
run your test suite.
|
||||
- `{package}` is the path to the package being built - the `package_dir`
|
||||
argument supplied to cibuildwheel on the command line.
|
||||
- `{project}` is an absolute path to the project root - the working
|
||||
directory where cibuildwheel was called.
|
||||
|
||||
On all platforms other than iOS, the command is run in a shell, so you can write things like `cmd1 && cmd2`.
|
||||
|
||||
@@ -1318,18 +1318,18 @@ Platform-specific environment variables are also available:<br/>
|
||||
```toml
|
||||
[tool.cibuildwheel]
|
||||
# Run the package tests using `pytest`
|
||||
test-command = "pytest ./tests"
|
||||
test-command = "pytest {project}/tests"
|
||||
|
||||
# Trigger an install of the package, but run nothing of note
|
||||
test-command = "echo Wheel installed"
|
||||
|
||||
# Multiline example
|
||||
test-command = [
|
||||
"pytest ./tests",
|
||||
"python ./test.py",
|
||||
"pytest {project}/tests",
|
||||
"python {project}/test.py",
|
||||
]
|
||||
|
||||
# run tests on ios
|
||||
# run tests on ios - when test-sources is set, use relative paths, not {project} or {package}
|
||||
[tool.cibuildwheel.ios]
|
||||
test-sources = ["tests"]
|
||||
test-command = "python -m pytest ./tests"
|
||||
@@ -1341,17 +1341,17 @@ Platform-specific environment variables are also available:<br/>
|
||||
|
||||
```yaml
|
||||
# Run the package tests using `pytest`
|
||||
CIBW_TEST_COMMAND: pytest ./tests
|
||||
CIBW_TEST_COMMAND: pytest {project}/tests
|
||||
|
||||
# Trigger an install of the package, but run nothing of note
|
||||
CIBW_TEST_COMMAND: "echo Wheel installed"
|
||||
|
||||
# Multi-line example - join with && on all platforms
|
||||
CIBW_TEST_COMMAND: >
|
||||
pytest ./tests &&
|
||||
python ./test.py
|
||||
pytest {project}/tests &&
|
||||
python {project}/test.py
|
||||
|
||||
# run tests on ios
|
||||
# run tests on ios - when test-sources is set, use relative paths, not {project} or {package}
|
||||
CIBW_TEST_SOURCES_IOS: tests
|
||||
CIBW_TEST_COMMAND_IOS: python -m pytest ./tests
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user