Skip to content

Commit 4305a9a

Browse files
authored
Merge pull request #2145 from davidhewitt/merge-pytests
pytests: merge benchmark and test crates
2 parents 5dd46e9 + 8b47f4f commit 4305a9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+132
-201
lines changed

.github/workflows/bench.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ jobs:
8383

8484
- name: Run benchmarks
8585
run: |
86-
cd pytests/pyo3-benchmarks
87-
pip install -r requirements-dev.txt
88-
pip install .
89-
pytest --benchmark-json ../../output.json --benchmark-enable
86+
pip install nox
87+
nox -f pytests/noxfile.py -s bench -- --benchmark-json $(pwd)/output.json
9088
- name: Store benchmark result
9189
uses: rhysd/github-action-benchmark@v1
9290
with:

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ harness = false
130130
[workspace]
131131
members = [
132132
"pyo3-ffi",
133+
"pyo3-build-config",
133134
"pyo3-macros",
134135
"pyo3-macros-backend",
135-
"pytests/pyo3-benchmarks",
136-
"pytests/pyo3-pytests",
136+
"pytests",
137137
"examples",
138138
"xtask"
139139
]

Contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you want to become familiar with the codebase, see
99

1010
## Getting started contributing
1111

12-
Please join in with any part of PyO3 which interests you. We use GitHub issues to record all bugs and ideas. Feel free to request an issue to be assigned to you if you want to work on it.
12+
Please join in with any part of PyO3 which interests you. We use GitHub issues to record all bugs and ideas. Feel free to request an issue to be assigned to you if you want to work on it.
1313

1414
You can browse the API of the non-public parts of PyO3 [here](https://pyo3.rs/internal/doc/pyo3/index.html).
1515

@@ -47,7 +47,7 @@ There are some specific areas of focus where help is currently needed for the do
4747
- Issues requesting documentation improvements are tracked with the [documentation](https://github.com/PyO3/pyo3/issues?q=is%3Aissue+is%3Aopen+label%3Adocumentation) label.
4848
- Not all APIs had docs or examples when they were made. The goal is to have documentation on all PyO3 APIs ([#306](https://github.com/PyO3/pyo3/issues/306)). If you see an API lacking a doc, please write one and open a PR!
4949

50-
You can build the docs (including all features) with
50+
You can build the docs (including all features) with
5151
```cargo +nightly pyo3_doc_scrape```
5252

5353
#### Doctests
@@ -115,7 +115,7 @@ First, there are Rust-based benchmarks located in the `benches` subdirectory. As
115115

116116
cargo +nightly bench
117117

118-
Second, there is a Python-based benchmark contained in the `pyo3-benchmarks` example. You can read more about it [here](examples/pyo3-benchmarks).
118+
Second, there is a Python-based benchmark contained in the `pytests` subdirectory. You can read more about it [here](pytests).
119119

120120
## Sponsor this project
121121

Makefile

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,22 @@ test: lint test_py
1414

1515
test_py:
1616
@for example in examples/*/noxfile.py; do echo "-- Running nox for $$example --"; nox -f $$example/noxfile.py || exit 1; echo ""; done
17-
@for package in pytests/*/noxfile.py; do echo "-- Running nox for $$package --"; nox -f $$package/noxfile.py || exit 1; echo ""; done
17+
echo "-- Running nox for pytests/noxfile.py --";
18+
nox -f pytests/noxfile.py || exit 1;
1819

1920
fmt_py:
2021
black . --check
2122

2223
fmt_rust:
2324
cargo fmt --all -- --check
24-
for package in pytests/*/; do cargo fmt --manifest-path $$package/Cargo.toml -- --check || exit 1; done
2525

2626
fmt: fmt_rust fmt_py
2727
@true
2828

29-
coverage:
30-
# cargo llvm-cov clean --workspace
31-
# cargo llvm-cov $(COVERAGE_PACKAGES) --no-report
32-
# cargo llvm-cov $(COVERAGE_PACKAGES) --no-report --features abi3
33-
# cargo llvm-cov $(COVERAGE_PACKAGES) --no-report --features $(ALL_ADDITIVE_FEATURES)
34-
# cargo llvm-cov $(COVERAGE_PACKAGES) --no-report --features abi3 $(ALL_ADDITIVE_FEATURES)
35-
bash -c "\
36-
set -a\
37-
source <(cargo llvm-cov show-env)\
38-
make test_py\
39-
"
40-
cargo llvm-cov $(COVERAGE_PACKAGES) --no-run --summary-only
41-
42-
4329
clippy:
4430
cargo clippy --features="$(ALL_ADDITIVE_FEATURES)" --all-targets --workspace -- -Dwarnings
4531
cargo clippy --features="abi3 $(ALL_ADDITIVE_FEATURES)" --all-targets --workspace -- -Dwarnings
4632
for example in examples/*/; do cargo clippy --manifest-path $$example/Cargo.toml -- -Dwarnings || exit 1; done
47-
for package in pytests/*/; do cargo clippy --manifest-path $$package/Cargo.toml -- -Dwarnings || exit 1; done
4833

4934
lint: fmt clippy
5035
@true

pytests/pyo3-pytests/Cargo.toml renamed to pytests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ description = "Python-based tests for PyO3"
66
edition = "2018"
77

88
[dependencies]
9-
pyo3 = { path = "../../", features = ["extension-module"] }
9+
pyo3 = { path = "../", features = ["extension-module"] }
1010

1111
[build-dependencies]
12-
pyo3-build-config = { path = "../../pyo3-build-config" }
12+
pyo3-build-config = { path = "../pyo3-build-config" }
1313

1414
[lib]
1515
name = "pyo3_pytests"
File renamed without changes.

pytests/README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
# PyO3 Python tests
1+
# pyo3-pytests
22

3-
These crates are a collection of test extension modules built with PyO3. They are all tested using `nox` in PyO3's CI.
3+
An extension module built using PyO3, used to test and benchmark PyO3 from Python.
44

5-
Below is a brief description of each of these:
5+
## Testing
66

7-
| Example | Description |
8-
| ------- | ----------- |
9-
| `pyo3-benchmarks` | A project containing some benchmarks of PyO3 functionality called from Python. |
10-
| `pyo3-pytests` | A project containing some tests of PyO3 functionality called from Python. |
7+
This package is intended to be built using `maturin`. Once built, you can run the tests using `pytest`:
8+
9+
```shell
10+
pip install maturin
11+
maturin develop
12+
pytest
13+
```
14+
15+
Alternatively, install nox and run the tests inside an isolated environment:
16+
17+
```shell
18+
nox
19+
```
20+
21+
## Running benchmarks
22+
23+
You can install the module in your Python environment and then run the benchmarks with pytest:
24+
25+
```shell
26+
pip install .
27+
pytest --benchmark-enable
28+
```
29+
30+
Or with nox:
31+
32+
```shell
33+
nox -s bench
34+
```
File renamed without changes.

pytests/pyo3-benchmarks/noxfile.py renamed to pytests/noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ def test(session):
1515
def bench(session):
1616
session.install("-rrequirements-dev.txt")
1717
session.install(".")
18-
session.run("pytest", "--benchmark-enable", *session.posargs)
18+
session.run("pytest", "--benchmark-enable", "--benchmark-only", *session.posargs)

pytests/pyo3-benchmarks/Cargo.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)