File tree 8 files changed +46
-13
lines changed
8 files changed +46
-13
lines changed Original file line number Diff line number Diff line change 1
1
2.8.0.dev (compared to 2.7.X)
2
2
-----------------------------
3
3
4
+ - change test module importing behaviour to append to sys.path
5
+ instead of prepending. This better allows to run test modules
6
+ against installated versions of a package even if the package
7
+ under test has the same import root. In this example::
8
+
9
+ testing/__init__.py
10
+ testing/test_pkg_under_test.py
11
+ pkg_under_test/
12
+
13
+ the tests will preferrably run against the installed version
14
+ of pkg_under_test whereas before they would always pick
15
+ up the local version. Thanks Holger Krekel.
16
+
4
17
5
18
2.7.1.dev (compared to 2.7.0)
6
19
-----------------------------
Original file line number Diff line number Diff line change 1
1
#
2
- __version__ = '2.8.0.dev1 '
2
+ __version__ = '2.8.0.dev2 '
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ def __init__(self, request):
254
254
break
255
255
self .tmpdir = tmpdir
256
256
self .plugins = []
257
- self ._syspathremove = []
257
+ self ._savesyspath = list ( sys . path )
258
258
self .chdir () # always chdir
259
259
self .request .addfinalizer (self .finalize )
260
260
@@ -270,8 +270,7 @@ def finalize(self):
270
270
has finished.
271
271
272
272
"""
273
- for p in self ._syspathremove :
274
- sys .path .remove (p )
273
+ sys .path [:] = self ._savesyspath
275
274
if hasattr (self , '_olddir' ):
276
275
self ._olddir .chdir ()
277
276
# delete modules that have been loaded from tmpdir
@@ -370,7 +369,6 @@ def syspathinsert(self, path=None):
370
369
if path is None :
371
370
path = self .tmpdir
372
371
sys .path .insert (0 , str (path ))
373
- self ._syspathremove .append (str (path ))
374
372
375
373
def mkdir (self , name ):
376
374
"""Create a new (sub)directory."""
Original file line number Diff line number Diff line change @@ -485,7 +485,7 @@ def collect(self):
485
485
def _importtestmodule (self ):
486
486
# we assume we are only called once per module
487
487
try :
488
- mod = self .fspath .pyimport (ensuresyspath = True )
488
+ mod = self .fspath .pyimport (ensuresyspath = "append" )
489
489
except SyntaxError :
490
490
raise self .CollectError (
491
491
py .code .ExceptionInfo ().getrepr (style = "short" ))
@@ -2062,3 +2062,4 @@ def get_scope_node(node, scope):
2062
2062
return node .session
2063
2063
raise ValueError ("unknown scope" )
2064
2064
return node .getparent (cls )
2065
+
Original file line number Diff line number Diff line change @@ -31,12 +31,12 @@ def get_version():
31
31
def has_environment_marker_support ():
32
32
"""
33
33
Tests that setuptools has support for PEP-426 environment marker support.
34
-
35
- The first known release to support it is 0.7 (and the earliest on PyPI seems to be 0.7.2
34
+
35
+ The first known release to support it is 0.7 (and the earliest on PyPI seems to be 0.7.2
36
36
so we're using that), see: http://pythonhosted.org/setuptools/history.html#id142
37
-
37
+
38
38
References:
39
-
39
+
40
40
* https://wheel.readthedocs.org/en/latest/index.html#defining-conditional-dependencies
41
41
* https://www.python.org/dev/peps/pep-0426/#environment-markers
42
42
"""
@@ -48,7 +48,7 @@ def has_environment_marker_support():
48
48
49
49
50
50
def main ():
51
- install_requires = ['py>=1.4.25 ' ]
51
+ install_requires = ['py>=1.4.27.dev2 ' ]
52
52
extras_require = {}
53
53
if has_environment_marker_support ():
54
54
extras_require [':python_version=="2.6" or python_version=="3.0" or python_version=="3.1"' ] = ['argparse' ]
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from textwrap import dedent
1
3
import pytest , py
2
4
3
5
class TestModule :
@@ -23,6 +25,24 @@ def test_import_duplicate(self, testdir):
23
25
"*HINT*" ,
24
26
])
25
27
28
+ def test_import_appends_for_import (self , testdir , monkeypatch ):
29
+ syspath = list (sys .path )
30
+ monkeypatch .setattr (sys , "path" , syspath )
31
+ root1 = testdir .mkdir ("root1" )
32
+ root2 = testdir .mkdir ("root2" )
33
+ root1 .ensure ("x456.py" )
34
+ root2 .ensure ("x456.py" )
35
+ p = root2 .join ("test_x456.py" )
36
+ p .write (dedent ("""\
37
+ import x456
38
+ def test():
39
+ assert x456.__file__.startswith(%r)
40
+ """ % str (root1 )))
41
+ syspath .insert (0 , str (root1 ))
42
+ with root2 .as_cwd ():
43
+ reprec = testdir .inline_run ()
44
+ reprec .assertoutcome (passed = 1 )
45
+
26
46
def test_syntax_error_in_module (self , testdir ):
27
47
modcol = testdir .getmodulecol ("this is a syntax error" )
28
48
pytest .raises (modcol .CollectError , modcol .collect )
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ def test_pytestconfig_is_session_scoped():
238
238
239
239
240
240
class TestNoselikeTestAttribute :
241
- def test_module (self , testdir ):
241
+ def test_module_with_global_test (self , testdir ):
242
242
testdir .makepyfile ("""
243
243
__test__ = False
244
244
def test_hello():
@@ -248,7 +248,7 @@ def test_hello():
248
248
assert not reprec .getfailedcollections ()
249
249
calls = reprec .getreports ("pytest_runtest_logreport" )
250
250
assert not calls
251
-
251
+
252
252
def test_class_and_method (self , testdir ):
253
253
testdir .makepyfile ("""
254
254
__test__ = True
Original file line number Diff line number Diff line change @@ -772,6 +772,7 @@ def test_default_markers(testdir):
772
772
])
773
773
774
774
def test_importplugin_issue375 (testdir ):
775
+ testdir .syspathinsert (testdir .tmpdir )
775
776
testdir .makepyfile (qwe = "import aaaa" )
776
777
excinfo = pytest .raises (ImportError , lambda : importplugin ("qwe" ))
777
778
assert "qwe" not in str (excinfo .value )
You can’t perform that action at this time.
0 commit comments