summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_api.py43
-rw-r--r--tests/test_process.py33
2 files changed, 43 insertions, 33 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index 47f90045..9a3fc820 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -401,6 +401,49 @@ class ApiTest(CoverageTest):
self.assertEqual(statements, [1, 2])
self.assertEqual(missing, [1, 2])
+ def test_warnings(self):
+ self.make_file("hello.py", """\
+ import sys, os
+ print("Hello")
+ """)
+ cov = coverage.Coverage(source=["sys", "xyzzy", "quux"])
+ self.start_import_stop(cov, "hello")
+ cov.get_data()
+
+ out = self.stdout()
+ self.assertIn("Hello\n", out)
+
+ err = self.stderr()
+ self.assertIn(textwrap.dedent("""\
+ Coverage.py warning: Module sys has no Python source. (module-not-python)
+ Coverage.py warning: Module xyzzy was never imported. (module-not-imported)
+ Coverage.py warning: Module quux was never imported. (module-not-imported)
+ Coverage.py warning: No data was collected. (no-data-collected)
+ """), err)
+
+ def test_warnings_suppressed(self):
+ self.make_file("hello.py", """\
+ import sys, os
+ print("Hello")
+ """)
+ self.make_file(".coveragerc", """\
+ [run]
+ disable_warnings = no-data-collected, module-not-imported
+ """)
+ cov = coverage.Coverage(source=["sys", "xyzzy", "quux"])
+ self.start_import_stop(cov, "hello")
+ cov.get_data()
+
+ out = self.stdout()
+ self.assertIn("Hello\n", out)
+
+ err = self.stderr()
+ self.assertIn(textwrap.dedent("""\
+ Coverage.py warning: Module sys has no Python source. (module-not-python)
+ """), err)
+ self.assertNotIn("module-not-imported", err)
+ self.assertNotIn("no-data-collected", err)
+
class NamespaceModuleTest(CoverageTest):
"""Test PEP-420 namespace modules."""
diff --git a/tests/test_process.py b/tests/test_process.py
index 16341f5d..2f30fa1f 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -484,39 +484,6 @@ class ProcessTest(CoverageTest):
data.read_file(".coverage")
self.assertEqual(data.line_counts()['fork.py'], 9)
- def test_warnings(self):
- self.make_file("hello.py", """\
- import sys, os
- print("Hello")
- """)
- out = self.run_command("coverage run --source=sys,xyzzy,quux hello.py")
-
- self.assertIn("Hello\n", out)
- self.assertIn(textwrap.dedent("""\
- Coverage.py warning: Module sys has no Python source. (module-not-python)
- Coverage.py warning: Module xyzzy was never imported. (module-not-imported)
- Coverage.py warning: Module quux was never imported. (module-not-imported)
- Coverage.py warning: No data was collected. (no-data-collected)
- """), out)
-
- def test_warnings_suppressed(self):
- self.make_file("hello.py", """\
- import sys, os
- print("Hello")
- """)
- self.make_file(".coveragerc", """\
- [run]
- disable_warnings = no-data-collected, module-not-imported
- """)
- out = self.run_command("coverage run --source=sys,xyzzy,quux hello.py")
-
- self.assertIn("Hello\n", out)
- self.assertIn(textwrap.dedent("""\
- Coverage.py warning: Module sys has no Python source. (module-not-python)
- """), out)
- self.assertNotIn("module-not-imported", out)
- self.assertNotIn("no-data-collected", out)
-
def test_warnings_during_reporting(self):
# While fixing issue #224, the warnings were being printed far too
# often. Make sure they're not any more.