Skip to content

Commit b766db8

Browse files
author
Auke Willem Oosterhoff
committed
Add note to FAQ about failing integration tests
Integration tests of a PyO3 project can't be put inside a `tests/` directory. Due to a known problem Cargo fails to import the crate. Fixes: PyO3#1321
1 parent 5170412 commit b766db8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

guide/src/faq.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ extension-module = ["pyo3/extension-module"]
2828
default = ["extension-module"]
2929
```
3030

31+
## I can't run `cargo test`: Compiler fails to import crate for tests in `tests/` directory!
32+
33+
The Rust book suggests to [put integration tests inside a `tests/` directory](https://doc.rust-lang.org/book/ch11-03-test-organization.html#integration-tests). However, you can't do that for a PyO3 project. The compiler wouldn't be able to find your crate and displays an error like this:
34+
35+
```
36+
error[E0463]: can't find crate for `my-crate`
37+
--> tests/tests.rs:4:1
38+
|
39+
4 | use crate;
40+
| ^^^^^^^^^ can't find crate
41+
```
42+
43+
This is not a bug in PyO3. But it's a [known problem of Cargo](https://github.com/rust-lang/cargo/issues/6659).
44+
45+
For now you can work around it by putting the integration tests inside the `src/` directory.
46+
3147
## Ctrl-C doesn't do anything while my Rust code is executing!
3248

3349
This is because Ctrl-C raises a SIGINT signal, which is handled by the calling Python process by simply setting a flag to action upon later. This flag isn't checked while Rust code called from Python is executing, only once control returns to the Python interpreter.

0 commit comments

Comments
 (0)