Skip to content

Commit 3eac3ca

Browse files
author
Daniil Galiev
committed
refactor disabling markers
1 parent 4cc6bca commit 3eac3ca

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/_pytest/python.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,14 @@ def _genfunctions(self, name, funcobj):
432432
class Module(nodes.File, PyCollector):
433433
""" Collector for test classes and functions. """
434434

435+
def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
436+
if fspath.basename == "__init__.py":
437+
self._ALLOW_MARKERS = False
438+
439+
nodes.FSCollector.__init__(
440+
self, fspath, parent=parent, config=config, session=session, nodeid=nodeid
441+
)
442+
435443
def _getobj(self):
436444
return self._importtestmodule()
437445

@@ -548,15 +556,6 @@ def _importtestmodule(self):
548556
return mod
549557

550558

551-
class InitModule(Module):
552-
_ALLOW_MARKERS = False
553-
554-
def __repr__(self):
555-
if type(self) == InitModule:
556-
return "<{} {}>".format(Module.__name__, getattr(self, "name", None))
557-
return super().__repr__()
558-
559-
560559
class Package(Module):
561560
def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
562561
session = parent.session
@@ -646,7 +645,7 @@ def collect(self):
646645
if init_module.check(file=1) and path_matches_patterns(
647646
init_module, self.config.getini("python_files")
648647
):
649-
yield InitModule(init_module, self)
648+
yield Module(init_module, self)
650649
pkg_prefixes = set()
651650
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):
652651
# We will visit our own __init__.py file, in which case we skip it.

0 commit comments

Comments
 (0)