New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
examples_test.py
cannot be run in parallel
#475
Labels
Comments
A simple fix that doesn't depend on diff --git a/test/examples_test.py b/test/examples_test.py
index 8fb82eac..531f0018 100644
--- a/test/examples_test.py
+++ b/test/examples_test.py
@@ -1,16 +1,28 @@
"""Test whether the examples are still working."""
import runpy
+import os
import pytest
+# There is https://github.com/RKrahl/pytest-dependency and
+# https://github.com/pytest-dev/pytest-order but we like to keep in simple
+# here. When running in parallel (pytest-xdist), we execute ex01 at most twice,
+# which is OK.
+def check_and_create_ex01_artifact():
+ if not os.path.exists("be_model.zip"):
+ print("Running example basic/ex01 in preparation another example")
+ runpy.run_path("../examples/basic/ex01_train_network.py")
+
+
@pytest.mark.examples
class TestExamples:
def test_basic_ex01(self):
runpy.run_path("../examples/basic/ex01_train_network.py")
def test_basic_ex02(self):
+ check_and_create_ex01_artifact()
runpy.run_path("../examples/basic/ex02_test_network.py")
def test_basic_ex03(self):
@@ -20,9 +32,11 @@ class TestExamples:
runpy.run_path("../examples/basic/ex04_hyperparameter_optimization.py")
def test_basic_ex05(self):
+ check_and_create_ex01_artifact()
runpy.run_path("../examples/basic/ex05_run_predictions.py")
def test_basic_ex06(self):
+ check_and_create_ex01_artifact()
runpy.run_path("../examples/basic/ex06_ase_calculator.py") |
elcorto
added a commit
to elcorto/mala
that referenced
this issue
Aug 31, 2023
elcorto
added a commit
to elcorto/mala
that referenced
this issue
Sep 7, 2023
elcorto
added a commit
to elcorto/mala
that referenced
this issue
Mar 18, 2024
elcorto
added a commit
to elcorto/mala
that referenced
this issue
Mar 18, 2024
elcorto
added a commit
to elcorto/mala
that referenced
this issue
Mar 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The order of test execution is given by the order of tests in a test script. In
examples_test.py
,test_basic_ex01
is run first, creatingbe_model.zip
, which is needed by some other tests in the script.When test are executed in parallel (e.g. using pytest-xdist), the order is random and some tests that depend on the existence of that artifact will fail.
The text was updated successfully, but these errors were encountered: