Skip to content

Commit

Permalink
Incorporated first round of feedback (pytest-dev#1597).
Browse files Browse the repository at this point in the history
  • Loading branch information
taschini committed Jun 9, 2016
1 parent 2481b7a commit 93f320a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 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
21 changes: 6 additions & 15 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 Down Expand Up @@ -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)
Expand Down

0 comments on commit 93f320a

Please sign in to comment.