pyo3: `dyld: Symbol not found: _PyExc_SystemError` in tests if there is `#[pymethods]` in project
Tests fail with error when there are methods in #[pymethods] impl for struct:
Compiling pyo3-test v0.1.0 (/Users/ivan/pyo3-test)
Finished dev [unoptimized + debuginfo] target(s) in 1.10s
Running target/debug/deps/pyo3_test-34e869060858761f
dyld: Symbol not found: _PyExc_SystemError
Referenced from: /Users/ivan/pyo3-test/target/debug/deps/pyo3_test-34e869060858761f
Expected in: flat namespace
in /Users/ivan/pyo3-test/target/debug/deps/pyo3_test-34e869060858761f
error: process didn't exit successfully: `/Users/ivan/pyo3-test/target/debug/deps/pyo3_test-34e869060858761f` (signal: 6, SIGABRT: process abort signal)
🌍 Environment
- Your operating system and version: macOS 10.14.2 (18C54)
- Your python version: 3.7.2
- How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: i don’t remeber, probably
brew install python3. I used virtualenv via pipenv - Your rust version (
rustc --version): 1.34.0-nightly (8ae730a44 2019-02-04) - Are you using the latest pyo3 version? Have you tried using latest master (replace
version = "0.x.y"withgit = "https://github.com/PyO3/pyo3")?I use 0.6.0-alpha.2. With latest master error is the same.
đź’Ą Reproducing
Run cargo test for the following code:
use pyo3::prelude::*;
#[pyclass]
struct Class {}
#[pymethods]
impl Class {
#[new]
fn __new__(obj: &PyRawObject) -> PyResult<()> {
obj.init(|| Class {})
}
}
#[pymodule]
fn pyo3_test(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Class>()
}
#[cfg(test)]
mod tests {
#[test]
fn test() {}
}
Also i created minimal project for reproducing the issue: https://github.com/deaz/pyo3-test
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 4
- Comments: 16 (9 by maintainers)
Commits related to this issue
- Showcase of PyO3/pyo3#340 and PyO3/pyo3#341. — committed to mvaled/pyo3bug340 by mvaled 6 years ago
- Disable compilation of bindings with test feature The bindings module does not play nicely with cargo test. Fortunatley, it's functionality is tested with pytest, and the module is not required when ... — committed to gustavgransbo/networkg by deleted user 6 years ago
- Move rust tests to a separate crate https://github.com/PyO3/pyo3/issues/340 — committed to icicle-emu/icicle-python by mrexodia 2 years ago
- Switch to a [workspace] https://github.com/PyO3/pyo3/issues/340 — committed to icicle-emu/icicle-python by mrexodia 2 years ago
- Move rust tests to a separate crate https://github.com/PyO3/pyo3/issues/340 — committed to icicle-emu/icicle-python by mrexodia 2 years ago
- Switch to a [workspace] https://github.com/PyO3/pyo3/issues/340 — committed to icicle-emu/icicle-python by mrexodia 2 years ago
First of all, thank you for the test repository!
As @kngwyu said, we need to deactivate features for the tests. A proper solution for this requires https://github.com/rust-lang/cargo/issues/2911, which unfortunately is unlikely to be implemented soon.
For now, you can use the following as workaround:
Tests can then be run with
cargo test --no-default-features, whilecargo buildstill works as expected.With a bit context this workaround would be very useful in the guide.
The work-around mentioned in https://github.com/PyO3/pyo3/issues/340#issuecomment-461514532 does not work if the test is run on a workspace where one of member crates uses PyO3.
As workaround I added
#[cfg(not(test))]to mystructandimpland it is working fineMaybe we’re going around this the wrong way, maybe when maturin builds it should add in --features=pyo3/extension-module because it knows it’s required. That way the cargo test would just work.
We can already do:
Why not add that flag in automatically if it’s clear that it’s not there? Having pyo3/extension-module turned on as a default feature seems like a footgun as people will just run cargo test and expect stuff to work on cli, IDEs etc.
I’ve posted this in the maturin issues list here: https://github.com/PyO3/maturin/issues/325