Issue #79 new

save() prevents harvesting on stop()?

Zooko O'Whielacronx
created an issue

Ned:

Looking at the source code of control.py in search of a different bug, it appears to me that if you call {{{save()}}} then it will set {{{self._harvested = True}}} which means that if you then accumulate more measurements and then call {{{stop()}}} that the {{{stop()}}} will observe that {{{self._harvested}}} is already {{{True}}} and will then fail to harvest the new measurements.

Comments (3)

  1. Ned Batchelder repo owner

    Hmm, I changed this logic (for other reasons), but this series of calls still won't save data: start(), ..., save(), ... stop(). Is it important that it work? Do you have a use case for it?

  2. Ned Batchelder repo owner

    Here's the test I tried that demonstrated the problem to me. It fails:

        def test_start_save_stop(self):
            self.make_file("code1.py", """\
                code1 = 1
                """)
            self.make_file("code2.py", """\
                code2 = 1
                code2 = 2
                """)
            cov = coverage.coverage()
            cov.start()
            self.import_local_file("code1")
            cov.save()
            self.import_local_file("code2")
            cov.stop()
    
            _, statements, missing, _ = cov.analysis("code1.py")
            self.assertEqual(statements, [1])
            self.assertEqual(missing, [])
            _, statements, missing, _ = cov.analysis("code2.py")
            self.assertEqual(statements, [1, 2])
            self.assertEqual(missing, [])
    
  3. Log in to comment