From a1358e4309ce089e883d3837547c9520158d8603 Mon Sep 17 00:00:00 2001 From: Nathan <95725385+treefern@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:41:40 +0000 Subject: [PATCH] NPI-3676 improve robustness of test_sp3_merge() unit test by cleaning up pyfakefs, which can persist data between runs --- tests/test_sp3.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_sp3.py b/tests/test_sp3.py index 2e7a468..38ebf30 100644 --- a/tests/test_sp3.py +++ b/tests/test_sp3.py @@ -230,10 +230,22 @@ class TestMergeSP3(TestCase): def setUp(self): self.setUpPyfakefs() + # Not sure if this is helpful + def tearDown(self): + self.tearDownPyfakefs() + def test_sp3merge(self): + # Surprisingly, this reset step must be done explicitly. The fake filesystem is backed by the real one, and + # the temp directory used may retain files from a previous run! + self.fs.reset() + # Create some fake files file_paths = ["/fake/dir/file1.sp3", "/fake/dir/file2.sp3"] - self.fs.create_file(file_paths[0], contents=input_data) + # Note this fails if the fake file has previously been created in the fakefs (which does actually exist somewhere on the real filesystem) + self.fs.create_file( + file_paths[0], + contents=input_data, + ) self.fs.create_file(file_paths[1], contents=input_data2) # Call the function to test