In the following on a M1 Max Macbook Pro, cargo run works fine, but cargo test results in an abort with "fatal runtime error: Rust cannot catch foreign exceptions"
use inline_python::python;
fn main() {
python! {
import matplotlib.pyplot as plt
plt.plot([1, 2], [3, 4])
plt.show()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_run() {
python! {
import matplotlib.pyplot as plt
plt.plot([1, 2], [3, 4])
plt.show()
}
}
}
This is because matplotlib (and many other GUI applications) must run on the main thread. An effective workaround is to run with -- --test-threads=1 so that tests all run on the main thread.
In the following on a M1 Max Macbook Pro,
cargo run
works fine, butcargo test
results in an abort with "fatal runtime error: Rust cannot catch foreign exceptions"