summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/cmdline.py4
-rw-r--r--tests/test_plugins.py19
3 files changed, 27 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 16599464..95a70c2d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -27,10 +27,14 @@ Latest
only once, no matter how many times it is called. This fixes problems due
to unusual virtualenv configurations (`issue 340`_).
+- Coverage.py now always adds the current directory to sys.path, so that
+ plugins can import files in the current directory (`issue 358`_).
+
.. _issue 117: https://bitbucket.org/ned/coveragepy/issue/117/enable-coverage-measurement-of-code-run-by
.. _issue 340: https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy
.. _issue 353: https://bitbucket.org/ned/coveragepy/issue/353/40a3-introduces-an-unexpected-third-case
.. _issue 357: https://bitbucket.org/ned/coveragepy/issue/357/behavior-changed-when-coveragerc-is
+.. _issue 358: https://bitbucket.org/ned/coveragepy/issue/358/all-coverage-commands-should-adjust
Version 4.0a4 --- 25 January 2015
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 4ef08f1d..2be32947 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -394,6 +394,10 @@ class CoverageScript(object):
if not self.args_ok(options, args):
return ERR
+ # We need to be able to import from the current directory, because
+ # plugins may try to, for example, to read Django settings.
+ sys.path[0] = ''
+
# Listify the list options.
source = unshell_list(options.source)
omit = unshell_list(options.omit)
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 0d57bc97..9cbe23b9 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -198,6 +198,25 @@ class PluginTest(CoverageTest):
]
self.assertEqual(expected_end, out_lines[-len(expected_end):])
+ def test_local_files_are_importable(self):
+ self.make_file("importing_plugin.py", """\
+ from coverage import CoveragePlugin
+ import local_module
+ class Plugin(CoveragePlugin):
+ pass
+ """)
+ self.make_file("local_module.py", "CONST = 1")
+ self.make_file(".coveragerc", """\
+ [run]
+ plugins = importing_plugin
+ """)
+ self.make_file("main_file.py", "print('MAIN')")
+
+ out = self.run_command("coverage run main_file.py")
+ self.assertEqual(out, "MAIN\n")
+ out = self.run_command("coverage html")
+ self.assertEqual(out, "")
+
class PluginWarningOnPyTracer(CoverageTest):
"""Test that we get a controlled exception with plugins on PyTracer."""