Skip to content

Commit

Permalink
Devops: Change tempfile to pytest's tmp_path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agoscinski authored and sphuber committed Oct 24, 2024
1 parent e269911 commit 309352f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,3 +860,17 @@ def factory(dirpath: pathlib.Path, read_bytes=True) -> dict:
return serialized

return factory


@pytest.fixture(scope='session')
def bash_path() -> Path:
run_process = subprocess.run(['which', 'bash'], capture_output=True, check=True)
path = run_process.stdout.decode('utf-8').strip()
return Path(path)


@pytest.fixture(scope='session')
def cat_path() -> Path:
run_process = subprocess.run(['which', 'cat'], capture_output=True, check=True)
path = run_process.stdout.decode('utf-8').strip()
return Path(path)
10 changes: 4 additions & 6 deletions tests/tools/pytest_fixtures/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
"""Test the pytest fixtures."""

import tempfile


def test_aiida_config():
def test_aiida_config(tmp_path_factory):
"""Test that ``aiida_config`` fixture is loaded by default and creates a config instance in temp directory."""
from aiida.manage.configuration import get_config
from aiida.manage.configuration.config import Config

config = get_config()
assert isinstance(config, Config)
assert config.dirpath.startswith(tempfile.gettempdir())
assert config.dirpath.startswith(str(tmp_path_factory.getbasetemp()))


def test_aiida_config_tmp(aiida_config_tmp):
def test_aiida_config_tmp(aiida_config_tmp, tmp_path_factory):
"""Test that ``aiida_config_tmp`` returns a config instance in temp directory."""
from aiida.manage.configuration.config import Config

assert isinstance(aiida_config_tmp, Config)
assert aiida_config_tmp.dirpath.startswith(tempfile.gettempdir())
assert aiida_config_tmp.dirpath.startswith(str(tmp_path_factory.getbasetemp()))


def test_aiida_profile():
Expand Down

0 comments on commit 309352f

Please sign in to comment.