Incorporated feedback (#1597).

Fixed problem caused in a test on Windows by file left open by PyPy and not immediately garbage collected.
This commit is contained in:
taschini 2016-06-09 08:22:11 +02:00
parent e2e6e31711
commit 4d9e293b4d
2 changed files with 13 additions and 20 deletions

View File

@ -664,9 +664,12 @@ class Session(FSCollector):
return x return x
if loader is None: if loader is None:
return x return x
# This method is sometimes invoked when AssertionRewritingHook, which
# does not define a get_filename method, is already in place:
try: try:
path = loader.get_filename() path = loader.get_filename()
except: except AttributeError:
# Retrieve path from AssertionRewritingHook:
path = loader.modules[x][0].co_filename path = loader.modules[x][0].co_filename
if loader.is_package(x): if loader.is_package(x):
path = os.path.dirname(path) path = os.path.dirname(path)

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import sys import sys
import _pytest._code import _pytest._code
@ -513,22 +514,12 @@ class TestInvocationVariants:
path = testdir.mkpydir("tpkg") path = testdir.mkpydir("tpkg")
path.join("test_hello.py").write('raise ImportError') path.join("test_hello.py").write('raise ImportError')
result = testdir.runpytest("--pyargs", "tpkg.test_hello") result = testdir.runpytest_subprocess("--pyargs", "tpkg.test_hello")
assert result.ret != 0 assert result.ret != 0
# Depending on whether the process running the test is the result.stdout.fnmatch_lines([
# same as the process parsing the command-line arguments, the "collected*0*items*/*1*errors"
# type of failure can be different: ])
if result.stderr.str() == '':
# Different processes
result.stdout.fnmatch_lines([
"collected*0*items*/*1*errors"
])
else:
# Same process
result.stderr.fnmatch_lines([
"ERROR:*file*or*package*not*found:*tpkg.test_hello"
])
def test_cmdline_python_package(self, testdir, monkeypatch): def test_cmdline_python_package(self, testdir, monkeypatch):
monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False) monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False)
@ -549,7 +540,7 @@ class TestInvocationVariants:
def join_pythonpath(what): def join_pythonpath(what):
cur = py.std.os.environ.get('PYTHONPATH') cur = py.std.os.environ.get('PYTHONPATH')
if cur: if cur:
return str(what) + ':' + cur return str(what) + os.pathsep + cur
return what return what
empty_package = testdir.mkpydir("empty_package") empty_package = testdir.mkpydir("empty_package")
monkeypatch.setenv('PYTHONPATH', join_pythonpath(empty_package)) monkeypatch.setenv('PYTHONPATH', join_pythonpath(empty_package))
@ -560,11 +551,10 @@ class TestInvocationVariants:
]) ])
monkeypatch.setenv('PYTHONPATH', join_pythonpath(testdir)) monkeypatch.setenv('PYTHONPATH', join_pythonpath(testdir))
path.join('test_hello.py').remove() result = testdir.runpytest("--pyargs", "tpkg.test_missing")
result = testdir.runpytest("--pyargs", "tpkg.test_hello")
assert result.ret != 0 assert result.ret != 0
result.stderr.fnmatch_lines([ result.stderr.fnmatch_lines([
"*not*found*test_hello*", "*not*found*test_missing*",
]) ])
def test_cmdline_python_namespace_package(self, testdir, monkeypatch): def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
@ -605,7 +595,7 @@ class TestInvocationVariants:
cur = py.std.os.environ.get('PYTHONPATH') cur = py.std.os.environ.get('PYTHONPATH')
if cur: if cur:
dirs += (cur,) dirs += (cur,)
return ':'.join(str(p) for p in dirs) return os.pathsep.join(str(p) for p in dirs)
monkeypatch.setenv('PYTHONPATH', join_pythonpath(*search_path)) monkeypatch.setenv('PYTHONPATH', join_pythonpath(*search_path))
for p in search_path: for p in search_path:
monkeypatch.syspath_prepend(p) monkeypatch.syspath_prepend(p)