diff options
author | Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> | 2023-05-25 12:36:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-25 12:36:24 -0700 |
commit | 55561405b8306953098130115859ca5f725ed0b9 (patch) | |
tree | ef7872fde62d37a305c83e355d198703dec96e95 | |
parent | 8eef458cea65902b8d751992455791f18c1e0e2e (diff) | |
download | spack-55561405b8306953098130115859ca5f725ed0b9.tar.gz spack-55561405b8306953098130115859ca5f725ed0b9.tar.bz2 spack-55561405b8306953098130115859ca5f725ed0b9.tar.xz spack-55561405b8306953098130115859ca5f725ed0b9.zip |
Bugfix/tests: write not append stand-alone test status (#37841)
-rw-r--r-- | lib/spack/spack/install_test.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/test/test_suite.py | 24 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/spack/spack/install_test.py b/lib/spack/spack/install_test.py index ef9caab055..2cdde481cc 100644 --- a/lib/spack/spack/install_test.py +++ b/lib/spack/spack/install_test.py @@ -460,7 +460,8 @@ class PackageTest: elif self.counts[TestStatus.PASSED] > 0: status = TestStatus.PASSED - _add_msg_to_file(self.tested_file, f"{status.value}") + with open(self.tested_file, "w") as f: + f.write(f"{status.value}\n") @contextlib.contextmanager diff --git a/lib/spack/spack/test/test_suite.py b/lib/spack/spack/test/test_suite.py index b3057e9c3d..a082ff6528 100644 --- a/lib/spack/spack/test/test_suite.py +++ b/lib/spack/spack/test/test_suite.py @@ -441,6 +441,30 @@ def test_write_tested_status( assert TestStatus(status) == expected +@pytest.mark.regression("37840") +def test_write_tested_status_no_repeats( + tmpdir, install_mockery_mutable_config, mock_fetch, mock_test_stage +): + """Emulate re-running the same stand-alone tests a second time.""" + s = spack.spec.Spec("trivial-smoke-test").concretized() + pkg = s.package + statuses = [TestStatus.PASSED, TestStatus.PASSED] + for i, status in enumerate(statuses): + pkg.tester.test_parts[f"test_{i}"] = status + pkg.tester.counts[status] += 1 + + pkg.tester.tested_file = tmpdir.join("test-log.txt") + pkg.tester.write_tested_status() + pkg.tester.write_tested_status() + + # The test should NOT result in a ValueError: invalid literal for int() + # with base 10: '2\n2' (i.e., the results being appended instead of + # written to the file). + with open(pkg.tester.tested_file, "r") as f: + status = int(f.read().strip("\n")) + assert TestStatus(status) == TestStatus.PASSED + + def test_check_special_outputs(tmpdir): """This test covers two related helper methods""" contents = """CREATE TABLE packages ( |