Skip to content

Commit 5403f27

Browse files
committed
Incorporated feedback (pytest-dev#1597).
Fixed problem caused in a test on Windows by file left open by PyPy and not immediately garbage collected.
1 parent 2481b7a commit 5403f27

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

_pytest/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,12 @@ def _tryconvertpyarg(self, x):
655655
return x
656656
if loader is None:
657657
return x
658+
# This method is sometimes invoked when AssertionRewritingHook, which
659+
# does not define a get_filename method, is already in place:
658660
try:
659661
path = loader.get_filename()
660-
except:
662+
except AttributeError:
663+
# Retrieve path from AssertionRewritingHook:
661664
path = loader.modules[x][0].co_filename
662665
if loader.is_package(x):
663666
path = os.path.dirname(path)

testing/acceptance_test.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import os
23
import sys
34

45
import _pytest._code
@@ -513,22 +514,12 @@ def test_pyargs_importerror(self, testdir, monkeypatch):
513514
path = testdir.mkpydir("tpkg")
514515
path.join("test_hello.py").write('raise ImportError')
515516

516-
result = testdir.runpytest("--pyargs", "tpkg.test_hello")
517+
result = testdir.runpytest_subprocess("--pyargs", "tpkg.test_hello")
517518
assert result.ret != 0
518519

519-
# Depending on whether the process running the test is the
520-
# same as the process parsing the command-line arguments, the
521-
# type of failure can be different:
522-
if result.stderr.str() == '':
523-
# Different processes
524-
result.stdout.fnmatch_lines([
525-
"collected*0*items*/*1*errors"
526-
])
527-
else:
528-
# Same process
529-
result.stderr.fnmatch_lines([
530-
"ERROR:*file*or*package*not*found:*tpkg.test_hello"
531-
])
520+
result.stdout.fnmatch_lines([
521+
"collected*0*items*/*1*errors"
522+
])
532523

533524
def test_cmdline_python_package(self, testdir, monkeypatch):
534525
monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False)
@@ -549,7 +540,7 @@ def test_cmdline_python_package(self, testdir, monkeypatch):
549540
def join_pythonpath(what):
550541
cur = py.std.os.environ.get('PYTHONPATH')
551542
if cur:
552-
return str(what) + ':' + cur
543+
return str(what) + os.pathsep + cur
553544
return what
554545
empty_package = testdir.mkpydir("empty_package")
555546
monkeypatch.setenv('PYTHONPATH', join_pythonpath(empty_package))
@@ -560,11 +551,10 @@ def join_pythonpath(what):
560551
])
561552

562553
monkeypatch.setenv('PYTHONPATH', join_pythonpath(testdir))
563-
path.join('test_hello.py').remove()
564-
result = testdir.runpytest("--pyargs", "tpkg.test_hello")
554+
result = testdir.runpytest("--pyargs", "tpkg.test_missing")
565555
assert result.ret != 0
566556
result.stderr.fnmatch_lines([
567-
"*not*found*test_hello*",
557+
"*not*found*test_missing*",
568558
])
569559

570560
def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
@@ -605,7 +595,7 @@ def join_pythonpath(*dirs):
605595
cur = py.std.os.environ.get('PYTHONPATH')
606596
if cur:
607597
dirs += (cur,)
608-
return ':'.join(str(p) for p in dirs)
598+
return os.pathsep.join(str(p) for p in dirs)
609599
monkeypatch.setenv('PYTHONPATH', join_pythonpath(*search_path))
610600
for p in search_path:
611601
monkeypatch.syspath_prepend(p)

0 commit comments

Comments
 (0)