Skip to content

Commit 309352f

Browse files
agoscinskisphuber
authored andcommitted
Devops: Change tempfile to pytest's tmp_path
pytest's tmp_path and tempfile returns a different directory on macOS Sonoma than tempfile therefore we change the tests tmp_path as it is also used in in the tests to create the config file.
1 parent e269911 commit 309352f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,17 @@ def factory(dirpath: pathlib.Path, read_bytes=True) -> dict:
860860
return serialized
861861

862862
return factory
863+
864+
865+
@pytest.fixture(scope='session')
866+
def bash_path() -> Path:
867+
run_process = subprocess.run(['which', 'bash'], capture_output=True, check=True)
868+
path = run_process.stdout.decode('utf-8').strip()
869+
return Path(path)
870+
871+
872+
@pytest.fixture(scope='session')
873+
def cat_path() -> Path:
874+
run_process = subprocess.run(['which', 'cat'], capture_output=True, check=True)
875+
path = run_process.stdout.decode('utf-8').strip()
876+
return Path(path)

tests/tools/pytest_fixtures/test_configuration.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
"""Test the pytest fixtures."""
22

3-
import tempfile
43

5-
6-
def test_aiida_config():
4+
def test_aiida_config(tmp_path_factory):
75
"""Test that ``aiida_config`` fixture is loaded by default and creates a config instance in temp directory."""
86
from aiida.manage.configuration import get_config
97
from aiida.manage.configuration.config import Config
108

119
config = get_config()
1210
assert isinstance(config, Config)
13-
assert config.dirpath.startswith(tempfile.gettempdir())
11+
assert config.dirpath.startswith(str(tmp_path_factory.getbasetemp()))
1412

1513

16-
def test_aiida_config_tmp(aiida_config_tmp):
14+
def test_aiida_config_tmp(aiida_config_tmp, tmp_path_factory):
1715
"""Test that ``aiida_config_tmp`` returns a config instance in temp directory."""
1816
from aiida.manage.configuration.config import Config
1917

2018
assert isinstance(aiida_config_tmp, Config)
21-
assert aiida_config_tmp.dirpath.startswith(tempfile.gettempdir())
19+
assert aiida_config_tmp.dirpath.startswith(str(tmp_path_factory.getbasetemp()))
2220

2321

2422
def test_aiida_profile():

0 commit comments

Comments
 (0)