diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-18 21:08:32 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-18 21:08:32 -0400 |
commit | c162735ee34c2d0a9fda69d1d83959be10df1602 (patch) | |
tree | bd83a9ce42dce6eedbd49ee6f2906df8f3612614 /test/test_process.py | |
parent | 328d5e5da5483ca2edaf72ba0f00ed445402452b (diff) | |
download | python-coveragepy-git-c162735ee34c2d0a9fda69d1d83959be10df1602.tar.gz |
A test for issue #56.
Diffstat (limited to 'test/test_process.py')
-rw-r--r-- | test/test_process.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/test_process.py b/test/test_process.py index e8e8c8be..3fc5f34f 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -203,3 +203,43 @@ class ProcessTest(CoverageTest): self.assertMultiLineEqual(out, "about to exit..\n") self.assertEqual(status, status2) self.assertEqual(status, 17) + + if hasattr(os, 'fork'): + def test_fork(self): + self.make_file("fork.py", """\ + import os + + def child(): + print('Child!') + + def main(): + ret = os.fork() + + if ret == 0: + child() + else: + os.waitpid(ret, 0) + + main() + """) + + out = self.run_command("coverage run -p fork.py") + self.assertEqual(out, 'Child!\n') + self.assertFalse(os.path.exists(".coverage")) + + # After running the forking program, there should be two + # .coverage.machine.123 files. + self.assertEqual(self.number_of_data_files(), 2) + + # Combine the parallel coverage data files into .coverage . + self.run_command("coverage -c") + self.assertTrue(os.path.exists(".coverage")) + + # After combining, there should be only the .coverage file. + self.assertEqual(self.number_of_data_files(), 1) + + # Read the coverage file and see that b_or_c.py has all 7 lines + # executed. + data = coverage.CoverageData() + data.read_file(".coverage") + self.assertEqual(data.summary()['fork.py'], 7) |