summaryrefslogtreecommitdiff
path: root/tests/test_oddball.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-10-06 07:14:18 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-10-06 07:14:18 -0400
commit3b8f4a0b86f8796f1e7925b9c6593a9d5198b437 (patch)
tree68f192e6be5ee3cb4cba489b860a951b75755c28 /tests/test_oddball.py
parent0101eff78ab68dcf8a8c20e06c24b68d8e4c45e6 (diff)
downloadpython-coveragepy-git-3b8f4a0b86f8796f1e7925b9c6593a9d5198b437.tar.gz
Protect ourselves from mock'ed os. #416
Diffstat (limited to 'tests/test_oddball.py')
-rw-r--r--tests/test_oddball.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index bca7f127..8f9e9707 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -441,3 +441,39 @@ class ExecTest(CoverageTest):
_, statements, missing, _ = cov.analysis("to_exec.py")
self.assertEqual(statements, [31])
self.assertEqual(missing, [])
+
+
+class MockingProtectionTest(CoverageTest):
+ """Tests about protecting ourselves from aggressive mocking.
+
+ https://bitbucket.org/ned/coveragepy/issues/416/coverage-40-is-causing-existing-unit-tests
+
+ """
+ def test_os_path_exists(self):
+ # To see if this test still detects the problem, change isolate_module
+ # in misc.py to simply return its argument. It should fail with a
+ # StopIteration error.
+ self.make_file("bug416.py", """\
+ import os.path
+
+ import mock
+
+ @mock.patch('os.path.exists')
+ def test_path_exists(mock_exists):
+ mock_exists.side_effect = [17]
+ print("in test")
+ import bug416a
+ print(bug416a.foo)
+ print(os.path.exists("."))
+
+ test_path_exists()
+ """)
+ self.make_file("bug416a.py", """\
+ print("bug416a.py")
+ foo = 23
+ """)
+
+ import py_compile
+ py_compile.compile("bug416a.py")
+ out = self.run_command("coverage run bug416.py")
+ self.assertEqual(out, "in test\nbug416a.py\n23\n17\n")