revert importing test module behaviour to prepend by default
This commit is contained in:
parent
2575053697
commit
a62d12634c
14
CHANGELOG
14
CHANGELOG
|
@ -105,18 +105,18 @@
|
|||
|
||||
- fix issue735: assertion failures on debug versions of Python 3.4+
|
||||
|
||||
- change test module importing behaviour to append to sys.path
|
||||
instead of prepending. This better allows to run test modules
|
||||
against installated versions of a package even if the package
|
||||
under test has the same import root. In this example::
|
||||
- new option ``--import-mode`` to allow to change test module importing
|
||||
behaviour to append to sys.path instead of prepending. This better allows
|
||||
to run test modules against installated versions of a package even if the
|
||||
package under test has the same import root. In this example::
|
||||
|
||||
testing/__init__.py
|
||||
testing/test_pkg_under_test.py
|
||||
pkg_under_test/
|
||||
|
||||
the tests will preferrably run against the installed version
|
||||
of pkg_under_test whereas before they would always pick
|
||||
up the local version. Thanks Holger Krekel.
|
||||
the tests will run against the installed version
|
||||
of pkg_under_test when ``--import-mode=append`` is used whereas
|
||||
by default they would always pick up the local version. Thanks Holger Krekel.
|
||||
|
||||
- pytester: add method ``TmpTestdir.delete_loaded_modules()``, and call it
|
||||
from ``inline_run()`` to allow temporary modules to be reloaded.
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
#
|
||||
__version__ = '2.8.0.dev5'
|
||||
# coding: utf-8
|
||||
# file generated by setuptools_scm
|
||||
# don't change, don't track in version control
|
||||
version = '2.7.4.dev394+ng2575053.d20150916'
|
||||
|
|
|
@ -173,6 +173,12 @@ def pytest_addoption(parser):
|
|||
help="prefixes or glob names for Python test function and "
|
||||
"method discovery")
|
||||
|
||||
group.addoption("--import-mode", default="prepend",
|
||||
choices=["prepend", "append"], dest="importmode",
|
||||
help="prepend/append to sys.path when importing test modules, "
|
||||
"default is to prepend.")
|
||||
|
||||
|
||||
def pytest_cmdline_main(config):
|
||||
if config.option.showfixtures:
|
||||
showfixtures(config)
|
||||
|
@ -557,8 +563,9 @@ class Module(pytest.File, PyCollector):
|
|||
|
||||
def _importtestmodule(self):
|
||||
# we assume we are only called once per module
|
||||
importmode = self.config.getoption("--import-mode")
|
||||
try:
|
||||
mod = self.fspath.pyimport(ensuresyspath="append")
|
||||
mod = self.fspath.pyimport(ensuresyspath=importmode)
|
||||
except SyntaxError:
|
||||
raise self.CollectError(
|
||||
py.code.ExceptionInfo().getrepr(style="short"))
|
||||
|
|
|
@ -27,7 +27,7 @@ class TestModule:
|
|||
"*HINT*",
|
||||
])
|
||||
|
||||
def test_import_appends_for_import(self, testdir, monkeypatch):
|
||||
def test_import_prepend_append(self, testdir, monkeypatch):
|
||||
syspath = list(sys.path)
|
||||
monkeypatch.setattr(sys, "path", syspath)
|
||||
root1 = testdir.mkdir("root1")
|
||||
|
@ -35,13 +35,15 @@ class TestModule:
|
|||
root1.ensure("x456.py")
|
||||
root2.ensure("x456.py")
|
||||
p = root2.join("test_x456.py")
|
||||
monkeypatch.syspath_prepend(str(root1))
|
||||
p.write(dedent("""\
|
||||
import x456
|
||||
def test():
|
||||
assert x456.__file__.startswith(%r)
|
||||
""" % str(root1)))
|
||||
syspath.insert(0, str(root1))
|
||||
""" % str(root2)))
|
||||
with root2.as_cwd():
|
||||
reprec = testdir.inline_run("--import-mode=append")
|
||||
reprec.assertoutcome(passed=0, failed=1)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue