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
commit403e51068a123733740a094e40cdd31ceb5e7c61 (patch)
treea27d665d77aeea97cec1d45e932347969dbc1930 /tests
parent67f905e4b7002d71d7ab33b87089a876eb4ef66c (diff)
downloadpython-coveragepy-git-403e51068a123733740a094e40cdd31ceb5e7c61.tar.gz
Don't warn that namespace packages have no code. #572
--HG-- extra : amend_source : 68f6e0ab140e77ede11bb40dc2ac515cfb6f2333
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 00000000..94bb2959
--- /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 00000000..0839688c
--- /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 90f96548..3a06da36 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):