From 55561405b8306953098130115859ca5f725ed0b9 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Thu, 25 May 2023 12:36:24 -0700 Subject: Bugfix/tests: write not append stand-alone test status (#37841) --- lib/spack/spack/install_test.py | 3 ++- lib/spack/spack/test/test_suite.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'lib') 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 ( -- cgit v1.2.3-60-g2f50