Merge pull request #3751 from nicoddemus/collect-file-bug

Workaround for #3742
This commit is contained in:
Ronny Pfannschmidt 2018-08-02 07:35:46 +02:00 committed by GitHub
commit ca0476953e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 2 deletions

View File

@ -482,6 +482,8 @@ class Session(nodes.FSCollector):
self.trace.root.indent -= 1
def _collect(self, arg):
from _pytest.python import Package
names = self._parsearg(arg)
argpath = names.pop(0)
paths = []
@ -503,7 +505,7 @@ class Session(nodes.FSCollector):
root = self._node_cache[pkginit]
else:
col = root._collectfile(pkginit)
if col:
if col and isinstance(col, Package):
root = col[0]
self._node_cache[root.fspath] = root

View File

@ -0,0 +1,10 @@
import pytest
class CustomItem(pytest.Item, pytest.File):
def runtest(self):
pass
def pytest_collect_file(path, parent):
return CustomItem(path, parent)

View File

@ -0,0 +1,2 @@
def test():
pass

View File

@ -1618,6 +1618,11 @@ class TestFixtureManagerParseFactories(object):
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
def test_collect_custom_items(self, testdir):
testdir.copy_example("fixtures/custom_item")
result = testdir.runpytest("foo")
result.stdout.fnmatch_lines("*passed*")
class TestAutouseDiscovery(object):
@pytest.fixture

View File

@ -647,7 +647,7 @@ class Test_getinitialnodes(object):
col = testdir.getnode(config, x)
assert isinstance(col, pytest.Module)
assert col.name == "x.py"
assert col.parent.parent.parent is None
assert col.parent.parent is None
for col in col.listchain():
assert col.config is config