From 00edc77691c60411cf00431fdc6788f8fceb886a Mon Sep 17 00:00:00 2001 From: GuySten <62616591+GuySten@users.noreply.github.com> Date: Sat, 30 Aug 2025 05:39:46 +0200 Subject: [PATCH] Change test order to run unit tests first. (#3533) Co-authored-by: Paul Romano --- openmc/cell.py | 6 +++--- openmc/config.py | 6 +++--- tests/unit_tests/test_config.py | 5 +++-- tools/ci/gha-script.sh | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index 672afe095..88aaebc8f 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -567,10 +567,10 @@ class Cell(IDManagerMixin): .. versionadded:: 0.14.0 """ # Create dummy universe but preserve used_ids - next_id = openmc.Universe.next_id + next_id = openmc.UniverseBase.next_id u = openmc.Universe(cells=[self]) - openmc.Universe.used_ids.remove(u.id) - openmc.Universe.next_id = next_id + openmc.UniverseBase.used_ids.remove(u.id) + openmc.UniverseBase.next_id = next_id return u.plot(*args, **kwargs) def create_xml_subelement(self, xml_element, memo=None): diff --git a/openmc/config.py b/openmc/config.py index e75973495..23d8e23a7 100644 --- a/openmc/config.py +++ b/openmc/config.py @@ -178,7 +178,7 @@ class _Config(MutableMapping): self[key] = previous_value -def _default_config() -> _Config: +def _default_config(**kwargs) -> _Config: """Create a configuration initialized from environment variables. This function checks for OPENMC_CROSS_SECTIONS, OPENMC_MG_CROSS_SECTIONS, @@ -192,11 +192,11 @@ def _default_config() -> _Config: A new configuration object. """ - config = _Config() + config = _Config(kwargs) for key,var in _Config._PATH_KEYS.items(): if var in os.environ: config[key] = os.environ[var] - + chain_file = config.get("chain_file") xs_path = config.get("cross_sections") if chain_file is None and xs_path is not None and xs_path.exists(): diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 242c59b5e..45e6a7e5a 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -13,6 +13,7 @@ def reset_config_and_env(): """A fixture to ensure each test has a clean config, env, and CWD.""" original_env = dict(os.environ) original_cwd = os.getcwd() + original_resolve_paths = openmc.config["resolve_paths"] # Reset environment variables that affect config for key in ['OPENMC_CROSS_SECTIONS', 'OPENMC_MG_CROSS_SECTIONS', 'OPENMC_CHAIN_FILE']: @@ -25,13 +26,13 @@ def reset_config_and_env(): try: yield finally: - # Restore environment and CWD + # Restore environment, CWD and resolve_paths os.environ.clear() os.environ.update(original_env) os.chdir(original_cwd) # Restore config one last time for safety between modules - openmc.config = _default_config() + openmc.config = _default_config(resolve_paths=original_resolve_paths) def test_config_basics(): diff --git a/tools/ci/gha-script.sh b/tools/ci/gha-script.sh index c7c634ffa..c0f754c32 100755 --- a/tools/ci/gha-script.sh +++ b/tools/ci/gha-script.sh @@ -14,5 +14,5 @@ if [[ $EVENT == 'y' ]]; then args="${args} --event " fi -# Run regression and unit tests -pytest --cov=openmc -v $args tests +# Run unit tests and then regression tests +pytest --cov=openmc -v $args tests/unit_tests tests/regression_tests