Some quotes I bumped into last week
[gromacs.git] / python_packaging / sample_restraint / tests / conftest.py
blob0e894b044a6dacdee66ff2db0b346890e34aa70a
1 """Configuration and fixtures for pytest."""
3 import pytest
4 import tempfile
5 import os
7 @pytest.fixture()
8 def cleandir():
9 """Provide a clean working directory for tests.
11 Example usage:
13 import os
14 import pytest
16 @pytest.mark.usefixtures("cleandir")
17 class TestDirectoryInit(object):
18 def test_cwd_starts_empty(self):
19 assert os.listdir(os.getcwd()) == []
20 with open("myfile", "w") as f:
21 f.write("hello")
23 def test_cwd_again_starts_empty(self):
24 assert os.listdir(os.getcwd()) == []
26 Ref: https://docs.pytest.org/en/latest/fixture.html#using-fixtures-from-classes-modules-or-projects
27 """
28 newpath = tempfile.mkdtemp()
29 os.chdir(newpath)
32 try:
33 from mpi4py import MPI
34 withmpi_only = pytest.mark.skipif(not MPI.Is_initialized() or MPI.COMM_WORLD.Get_size() < 2,
35 reason="Test requires at least 2 MPI ranks, but MPI is not initialized or too small.")
36 except ImportError:
37 withmpi_only = pytest.mark.skip(reason="Test requires at least 2 MPI ranks, but mpi4py is not available.")
39 @pytest.fixture()
40 def tpr_filename():
41 """Provide a sample TPR file by filename."""
42 current_dir = os.path.dirname(__file__)
43 file_path = os.path.join(current_dir, 'topol.tpr')
44 return os.path.abspath(file_path)