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. --HG-- branch : prefer_installed
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import sys
|
||||
from textwrap import dedent
|
||||
import pytest, py
|
||||
|
||||
class TestModule:
|
||||
@@ -23,6 +25,24 @@ class TestModule:
|
||||
"*HINT*",
|
||||
])
|
||||
|
||||
def test_import_appends_for_import(self, testdir, monkeypatch):
|
||||
syspath = list(sys.path)
|
||||
monkeypatch.setattr(sys, "path", syspath)
|
||||
root1 = testdir.mkdir("root1")
|
||||
root2 = testdir.mkdir("root2")
|
||||
root1.ensure("x456.py")
|
||||
root2.ensure("x456.py")
|
||||
p = root2.join("test_x456.py")
|
||||
p.write(dedent("""\
|
||||
import x456
|
||||
def test():
|
||||
assert x456.__file__.startswith(%r)
|
||||
""" % str(root1)))
|
||||
syspath.insert(0, str(root1))
|
||||
with root2.as_cwd():
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
def test_syntax_error_in_module(self, testdir):
|
||||
modcol = testdir.getmodulecol("this is a syntax error")
|
||||
pytest.raises(modcol.CollectError, modcol.collect)
|
||||
|
||||
@@ -238,7 +238,7 @@ def test_pytestconfig_is_session_scoped():
|
||||
|
||||
|
||||
class TestNoselikeTestAttribute:
|
||||
def test_module(self, testdir):
|
||||
def test_module_with_global_test(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
__test__ = False
|
||||
def test_hello():
|
||||
@@ -248,7 +248,7 @@ class TestNoselikeTestAttribute:
|
||||
assert not reprec.getfailedcollections()
|
||||
calls = reprec.getreports("pytest_runtest_logreport")
|
||||
assert not calls
|
||||
|
||||
|
||||
def test_class_and_method(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
__test__ = True
|
||||
|
||||
Reference in New Issue
Block a user