diff --git a/CHANGELOG b/CHANGELOG index 5ba93603a..955d8f914 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Changes between 2.1.3 and [next version] ---------------------------------------- - fix issue83: link to generated funcarg list +- fix issue74: pyarg module names are now checked against imp.find_module false positives Changes between 2.1.2 and 2.1.3 ---------------------------------------- diff --git a/_pytest/main.py b/_pytest/main.py index d0d7c2dc3..f5a12fd5e 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -11,6 +11,8 @@ EXIT_TESTSFAILED = 1 EXIT_INTERRUPTED = 2 EXIT_INTERNALERROR = 3 +name_re = py.std.re.compile("^[a-zA-Z_]\w*$") + def pytest_addoption(parser): parser.addini("norecursedirs", "directory patterns to avoid for recursion", type="args", default=('.*', 'CVS', '_darcs', '{arch}')) @@ -472,6 +474,13 @@ class Session(FSCollector): mod = None path = [os.path.abspath('.')] + sys.path for name in x.split('.'): + # ignore anything thats not a propper name here + # else something like --pyargs will mess up '.' + # since imp.find_module will actually sometimes works for it + # but its supposed to be considered a filesystem path + # not a package + if name_re.match(name) is None: + return x try: fd, mod, type_ = imp.find_module(name, path) except ImportError: diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 55a486c6b..b0d365179 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -408,6 +408,14 @@ class TestInvocationVariants: result.stdout.fnmatch_lines([ "*2 passed*" ]) + + result = testdir.runpytest("--pyargs", ".") + assert result.ret == 0 + result.stdout.fnmatch_lines([ + "*2 passed*" + ]) + + monkeypatch.setenv('PYTHONPATH', testdir) path.join('test_hello.py').remove() result = testdir.runpytest("--pyargs", "tpkg.test_hello") assert result.ret != 0