Skip to content

Commit

Permalink
Incorporated feedback (pytest-dev#1597).
Browse files Browse the repository at this point in the history
Fixed problem caused in a test on Windows by file left open by PyPy and not immediately garbage collected.
  • Loading branch information
taschini committed Jun 13, 2016
1 parent 2481b7a commit 5403f27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
5 changes: 4 additions & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,12 @@ def _tryconvertpyarg(self, x):
return x
if loader is None:
return x
# This method is sometimes invoked when AssertionRewritingHook, which
# does not define a get_filename method, is already in place:
try:
path = loader.get_filename()
except:
except AttributeError:
# Retrieve path from AssertionRewritingHook:
path = loader.modules[x][0].co_filename
if loader.is_package(x):
path = os.path.dirname(path)
Expand Down
28 changes: 9 additions & 19 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
import sys

import _pytest._code
Expand Down Expand Up @@ -513,22 +514,12 @@ def test_pyargs_importerror(self, testdir, monkeypatch):
path = testdir.mkpydir("tpkg")
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

# Depending on whether the process running the test is the
# same as the process parsing the command-line arguments, the
# 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"
])
result.stdout.fnmatch_lines([
"collected*0*items*/*1*errors"
])

def test_cmdline_python_package(self, testdir, monkeypatch):
monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False)
Expand All @@ -549,7 +540,7 @@ def test_cmdline_python_package(self, testdir, monkeypatch):
def join_pythonpath(what):
cur = py.std.os.environ.get('PYTHONPATH')
if cur:
return str(what) + ':' + cur
return str(what) + os.pathsep + cur
return what
empty_package = testdir.mkpydir("empty_package")
monkeypatch.setenv('PYTHONPATH', join_pythonpath(empty_package))
Expand All @@ -560,11 +551,10 @@ def join_pythonpath(what):
])

monkeypatch.setenv('PYTHONPATH', join_pythonpath(testdir))
path.join('test_hello.py').remove()
result = testdir.runpytest("--pyargs", "tpkg.test_hello")
result = testdir.runpytest("--pyargs", "tpkg.test_missing")
assert result.ret != 0
result.stderr.fnmatch_lines([
"*not*found*test_hello*",
"*not*found*test_missing*",
])

def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
Expand Down Expand Up @@ -605,7 +595,7 @@ def join_pythonpath(*dirs):
cur = py.std.os.environ.get('PYTHONPATH')
if 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))
for p in search_path:
monkeypatch.syspath_prepend(p)
Expand Down

0 comments on commit 5403f27

Please sign in to comment.