From 5cefcb20522e3d48282ba3f889162be5ef8e9040 Mon Sep 17 00:00:00 2001 From: Daniil Galiev Date: Sat, 28 Sep 2019 00:06:46 +0500 Subject: [PATCH] refactor disabling markers --- src/_pytest/python.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index a1f6d5067..45a4e66a9 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -432,6 +432,14 @@ class PyCollector(PyobjMixin, nodes.Collector): class Module(nodes.File, PyCollector): """ Collector for test classes and functions. """ + def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None): + if fspath.basename == "__init__.py": + self._ALLOW_MARKERS = False + + nodes.FSCollector.__init__( + self, fspath, parent=parent, config=config, session=session, nodeid=nodeid + ) + def _getobj(self): return self._importtestmodule() @@ -548,15 +556,6 @@ class Module(nodes.File, PyCollector): return mod -class InitModule(Module): - _ALLOW_MARKERS = False - - def __repr__(self): - if type(self) == InitModule: - return "<{} {}>".format(Module.__name__, getattr(self, "name", None)) - return super().__repr__() - - class Package(Module): def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None): session = parent.session @@ -646,7 +645,7 @@ class Package(Module): if init_module.check(file=1) and path_matches_patterns( init_module, self.config.getini("python_files") ): - yield InitModule(init_module, self) + yield Module(init_module, self) pkg_prefixes = set() for path in this_path.visit(rec=self._recurse, bf=True, sort=True): # We will visit our own __init__.py file, in which case we skip it.