diff options
-rw-r--r-- | coverage/cmdline.py | 9 | ||||
-rw-r--r-- | coverage/control.py | 21 | ||||
-rw-r--r-- | test/test_cmdline.py | 26 | ||||
-rw-r--r-- | test/test_process.py | 2 |
4 files changed, 24 insertions, 34 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index b739afab..1ce5e0f5 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -511,7 +511,7 @@ class CoverageScript(object): if 'execute' in options.actions: # Run the script. self.coverage.start() - never_run = False + code_ran = True try: try: if options.module: @@ -519,11 +519,12 @@ class CoverageScript(object): else: self.run_python_file(args[0], args) except NoSource: - never_run = True + code_ran = False raise finally: - self.coverage.stop(never_run) - self.coverage.save() + if code_ran: + self.coverage.stop() + self.coverage.save() if 'combine' in options.actions: self.coverage.combine() diff --git a/coverage/control.py b/coverage/control.py index 6fc1b98d..514f23d9 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -172,10 +172,6 @@ class coverage(object): # Only _harvest_data once per measurement cycle. self._harvested = False - - # When stop() is called, we can tell it that in fact no product code - # was run, to make the warnings more reasonable. - self._never_run = False # Set the reporting precision. Numbers.set_precision(self.config.precision) @@ -365,14 +361,8 @@ class coverage(object): self._harvested = False self.collector.start() - def stop(self, never_run=False): - """Stop measuring code coverage. - - Set `never_run` to True to indicate that no product code was run, so - we don't warn unnecessarily. - - """ - self._never_run = never_run + def stop(self): + """Stop measuring code coverage.""" self.collector.stop() self._harvest_data() @@ -454,10 +444,9 @@ class coverage(object): self._warn("Module %s was never imported." % pkg) # Find out if we got any data. - if not self._never_run: - summary = self.data.summary() - if not summary: - self._warn("No data was collected.") + summary = self.data.summary() + if not summary: + self._warn("No data was collected.") # Find files that were never executed at all. for src in self.source: diff --git a/test/test_cmdline.py b/test/test_cmdline.py index f0f9d22f..d4cc763d 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -111,7 +111,7 @@ class ClassicCmdLineTest(CmdLineTest): .load() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) # -e -x calls coverage.erase first. @@ -120,7 +120,7 @@ class ClassicCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) # --timid sets a flag, and program arguments get passed through. @@ -129,7 +129,7 @@ class ClassicCmdLineTest(CmdLineTest): .load() .start() .run_python_file('foo.py', ['foo.py', 'abc', '123']) - .stop(False) + .stop() .save() """) # -L sets a flag, and flags for the program don't confuse us. @@ -138,7 +138,7 @@ class ClassicCmdLineTest(CmdLineTest): .load() .start() .run_python_file('foo.py', ['foo.py', '-a', '-b']) - .stop(False) + .stop() .save() """) @@ -470,7 +470,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --rcfile=myrc.rc foo.py", """\ @@ -478,7 +478,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --include=pre1,pre2 foo.py", """\ @@ -486,7 +486,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --omit=opre1,opre2 foo.py", """\ @@ -494,7 +494,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --include=pre1,pre2 --omit=opre1,opre2 foo.py", @@ -506,7 +506,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --source=quux,hi.there,/home/bar foo.py", @@ -518,7 +518,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_file('foo.py', ['foo.py']) - .stop(False) + .stop() .save() """) @@ -528,7 +528,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_module('mymodule', ['mymodule']) - .stop(False) + .stop() .save() """) self.cmd_executes("run -m mymodule -qq arg1 arg2", """\ @@ -536,7 +536,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_module('mymodule', ['mymodule', '-qq', 'arg1', 'arg2']) - .stop(False) + .stop() .save() """) self.cmd_executes("run --branch -m mymodule", """\ @@ -544,7 +544,7 @@ class NewCmdLineTest(CmdLineTest): .erase() .start() .run_python_module('mymodule', ['mymodule']) - .stop(False) + .stop() .save() """) self.cmd_executes_same("run -m mymodule", "run --module mymodule") diff --git a/test/test_process.py b/test/test_process.py index 8a47bfc7..917abc70 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -275,7 +275,7 @@ class ProcessTest(CoverageTest): Coverage.py warning: Module quux was never imported. Coverage.py warning: No data was collected. """) in out) - + def test_warnings_if_never_run(self): out = self.run_command("coverage run i_dont_exist.py") self.assertTrue("No file to run: 'i_dont_exist.py'" in out) |