diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..cd5dfff --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,27 @@ +import os +import pytest +import shlex +import subprocess + + +@pytest.fixture(autouse=True) +def wrapper(): + """ + A wrapper function that clears the environment variables before each test + and stops the EMLE server after each test. + """ + + # Clear the environment. + + for env in os.environ: + if env.startswith("EMLE_"): + del os.environ[env] + + yield + + # Stop the EMLE server. + process = subprocess.run( + shlex.split("emle-stop"), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) diff --git a/tests/test_external.py b/tests/test_external.py index f87e2e5..f9e831f 100644 --- a/tests/test_external.py +++ b/tests/test_external.py @@ -6,22 +6,6 @@ import tempfile -@pytest.fixture(autouse=True) -def teardown(): - """ - Clean up the environment. - """ - - yield - - # Stop the EMLE server. - process = subprocess.run( - shlex.split("emle-stop"), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - - def test_external_local_directory(): """ Make sure that the server can run using an external callback for the in diff --git a/tests/test_interpolate.py b/tests/test_interpolate.py index 4e1fbe6..7a2a07f 100644 --- a/tests/test_interpolate.py +++ b/tests/test_interpolate.py @@ -7,22 +7,6 @@ import tempfile -@pytest.fixture(autouse=True) -def teardown(): - """ - Clean up the environment. - """ - - yield - - # Stop the EMLE server. - process = subprocess.run( - shlex.split("emle-stop"), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - - def parse_mdinfo(mdinfo_file): """ Helper function to extract the total energy from AMBER mdinfo files. diff --git a/tests/test_qm_xyz.py b/tests/test_qm_xyz.py index 0564430..b015054 100644 --- a/tests/test_qm_xyz.py +++ b/tests/test_qm_xyz.py @@ -6,22 +6,6 @@ import tempfile -@pytest.fixture(autouse=True) -def teardown(): - """ - Clean up the environment. - """ - - yield - - # Stop the EMLE server. - process = subprocess.run( - shlex.split("emle-stop"), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - - def test_qm_xyz(): """ Make sure that an xyz file for the QM region is written when requested.