summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-05-04 21:18:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-05-04 21:18:43 -0400
commit594eb5ba5b69956bfd4c12e03c4e2c7c1155302a (patch)
tree2d754887461f0198c5becfa81a4eb74bd95ccc42 /tests
parente062672509aea7cc7fb302c5f086a26ec6840989 (diff)
downloadpython-coveragepy-594eb5ba5b69956bfd4c12e03c4e2c7c1155302a.tar.gz
Don't warn that namespace packages have no code. #572
Diffstat (limited to 'tests')
-rw-r--r--tests/modules/namespace_420/sub1/__init__.py4
-rw-r--r--tests/moremodules/namespace_420/sub2/__init__.py4
-rw-r--r--tests/test_api.py17
3 files changed, 21 insertions, 4 deletions
diff --git a/tests/modules/namespace_420/sub1/__init__.py b/tests/modules/namespace_420/sub1/__init__.py
new file mode 100644
index 0000000..94bb295
--- /dev/null
+++ b/tests/modules/namespace_420/sub1/__init__.py
@@ -0,0 +1,4 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+sub1 = "namespace_420 sub1"
diff --git a/tests/moremodules/namespace_420/sub2/__init__.py b/tests/moremodules/namespace_420/sub2/__init__.py
new file mode 100644
index 0000000..0839688
--- /dev/null
+++ b/tests/moremodules/namespace_420/sub2/__init__.py
@@ -0,0 +1,4 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+sub2 = "namespace_420 sub2"
diff --git a/tests/test_api.py b/tests/test_api.py
index 90f9654..3a06da3 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -445,7 +445,7 @@ class ApiTest(CoverageTest):
self.assertNotIn("no-data-collected", err)
-class NamespaceModuleTest(CoverageTest):
+class NamespaceModuleTest(UsingModulesMixin, CoverageTest):
"""Test PEP-420 namespace modules."""
def setUp(self):
@@ -454,14 +454,23 @@ class NamespaceModuleTest(CoverageTest):
self.skipTest("Python before 3.3 doesn't have namespace packages")
def test_explicit_namespace_module(self):
- self.make_file("namespace/package/module.py", "VAR = 1\n")
- self.make_file("main.py", "import namespace\n")
+ self.make_file("main.py", "import namespace_420\n")
cov = coverage.Coverage()
self.start_import_stop(cov, "main")
with self.assertRaisesRegex(CoverageException, r"Module .* has no file"):
- cov.analysis(sys.modules['namespace'])
+ cov.analysis(sys.modules['namespace_420'])
+
+ def test_bug_572(self):
+ self.make_file("main.py", "import namespace_420\n")
+
+ # Use source=namespace_420 to trigger the check that used to fail,
+ # and use source=main so that something is measured.
+ cov = coverage.Coverage(source=["namespace_420", "main"])
+ with self.assert_warnings(cov, []):
+ self.start_import_stop(cov, "main")
+ cov.report()
class OmitIncludeTestsMixin(UsingModulesMixin, CoverageTestMethodsMixin):