Improve --pyargs.
Don't evaluate modules and do nto show 'module not found' if ImportError is thrown in the module.
This commit is contained in:
parent
8675cf640d
commit
0e05a4fbcf
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest, _pytest
|
import pytest, _pytest
|
||||||
import os, sys
|
import os, sys, imp
|
||||||
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
||||||
|
|
||||||
# exitcodes for the command line
|
# exitcodes for the command line
|
||||||
|
@ -469,16 +469,22 @@ class Session(FSCollector):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _tryconvertpyarg(self, x):
|
def _tryconvertpyarg(self, x):
|
||||||
try:
|
mod = None
|
||||||
mod = __import__(x, None, None, ['__doc__'])
|
path = [os.path.abspath('.')] + sys.path
|
||||||
except (ValueError, ImportError):
|
for name in x.split('.'):
|
||||||
return x
|
try:
|
||||||
p = py.path.local(mod.__file__)
|
fd, mod, type_ = imp.find_module(name, path)
|
||||||
if p.purebasename == "__init__":
|
except ImportError:
|
||||||
p = p.dirpath()
|
return x
|
||||||
else:
|
else:
|
||||||
p = p.new(basename=p.purebasename+".py")
|
if fd is not None:
|
||||||
return str(p)
|
fd.close()
|
||||||
|
|
||||||
|
if type_[2] != imp.PKG_DIRECTORY:
|
||||||
|
path = [os.path.dirname(mod)]
|
||||||
|
else:
|
||||||
|
path = [mod]
|
||||||
|
return mod
|
||||||
|
|
||||||
def _parsearg(self, arg):
|
def _parsearg(self, arg):
|
||||||
""" return (fspath, names) tuple after checking the file exists. """
|
""" return (fspath, names) tuple after checking the file exists. """
|
||||||
|
|
Loading…
Reference in New Issue