Skip to content

Commit 5a53d1a

Browse files
committed
Add a test_test_repro_determinism test
1 parent be5b708 commit 5a53d1a

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

tests/config_tests/test_test_bit_reproducibility.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def base_test_command(self):
213213
# Minimal test command
214214
test_cmd = (
215215
"model-config-tests -s "
216-
# Use -k to select one test
217-
f"-k {self.test_name} "
216+
# Use -m to specify the test (each repro test has a unique marker)
217+
f"-m {self.test_name.removeprefix('test_')} "
218218
f"--output-path {self.output_path} "
219219
# Keep archive flag will keep any pre-existing archive for the test
220220
# and disable the actual 'payu run' steps
@@ -500,3 +500,31 @@ def check_checksum(output_path, checksum_path, model_name, match=True):
500500
assert test_checksum.read_text() == checksum_path.read_text()
501501
else:
502502
assert test_checksum.read_text() != checksum_path.read_text()
503+
504+
505+
@pytest.mark.parametrize("fail", [False, True])
506+
def test_test_repro_determinism(tmp_dir, fail):
507+
"""Test repro determinism for some example output"""
508+
test_name = "test_repro_determinism"
509+
510+
exp1_name = "exp_1d_runtime"
511+
exp2_name = "exp_1d_runtime_repeat"
512+
513+
# Setup some example files for both experiments
514+
exp1_helper = CommonTestHelper(test_name, exp1_name, "access", tmp_dir)
515+
exp1_helper.copy_config("release-preindustrial+concentrations")
516+
exp1_helper.create_mock_output("output000", modify=False)
517+
518+
exp2_helper = CommonTestHelper(test_name, exp2_name, "access", tmp_dir)
519+
exp2_helper.create_mock_output("output000", modify=fail)
520+
521+
# Build test command
522+
test_cmd = (
523+
f"{exp1_helper.base_test_command()} "
524+
f"--control-path {exp1_helper.control_path} "
525+
)
526+
527+
# Run test in a subprocess call
528+
result = subprocess.run(shlex.split(test_cmd), capture_output=True, text=True)
529+
# Check test result
530+
assert result.returncode == int(fail)

0 commit comments

Comments
 (0)