Skip to content

Commit 59e0e5a

Browse files
Merge pull request #5102 from springfall2008/fix/per-test-fixture-isolation
test: give each test its own PredBat rather than sharing one (#5079)
2 parents 45e3562 + 89bf8e9 commit 59e0e5a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎apps/predbat/unit_test.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ def main():
819819
sys.exit(0)
820820

821821
print("**** Starting Predbat tests ****")
822+
# Used by the debug-file, random-scenario and profiling paths below. The registry test
823+
# loop does not share this one - it builds a fresh instance per test (see GH#5079).
822824
my_predbat = create_predbat()
823825
print("**** Testing Predbat ****")
824826
failed = False
@@ -897,6 +899,13 @@ def main():
897899
# still running (or one that hung) is identified by its unmatched start stamp.
898900
print(f"**** Running: {name} - {desc} (start {time.strftime('%H:%M:%S')}) ****")
899901

902+
# Each test gets a PredBat of its own, so state an earlier test left behind cannot
903+
# reach it. Sharing one instance across the whole run made a test that mutated it
904+
# without restoring break whichever unrelated test happened to follow, depending on
905+
# the order they ran in (GH#5079). create_predbat() costs about 22ms, which is lost
906+
# in the noise of the suite as a whole.
907+
my_predbat = create_predbat()
908+
900909
start_time = time.time()
901910
test_failed = func(my_predbat)
902911
elapsed = time.time() - start_time

0 commit comments

Comments
 (0)