diff --git a/_pytest/main.py b/_pytest/main.py index 76a4fc128e9..2f2d6c26f2c 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -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) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index c66a1740f11..91854367e51 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os import sys import _pytest._code @@ -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) @@ -605,7 +596,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)