From 309352f8bf29e52057bd31153858eb8a3560e704 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Tue, 6 Aug 2024 08:35:45 +0200 Subject: [PATCH] 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. --- tests/conftest.py | 14 ++++++++++++++ tests/tools/pytest_fixtures/test_configuration.py | 10 ++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3a9cd56336..d4ca5ee1db 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/tools/pytest_fixtures/test_configuration.py b/tests/tools/pytest_fixtures/test_configuration.py index 574d0d4f6a..954e50fa66 100644 --- a/tests/tools/pytest_fixtures/test_configuration.py +++ b/tests/tools/pytest_fixtures/test_configuration.py @@ -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():