diff --git a/AUTHORS b/AUTHORS index e11400c1f..d0e584f63 100644 --- a/AUTHORS +++ b/AUTHORS @@ -70,6 +70,7 @@ Daniel Hahler Daniel Nuri Daniel Wandschneider Danielle Jenkins +Daniil Galiev Dave Hunt David Díaz-Barquero David Mohr diff --git a/changelog/5830.bugfix.rst b/changelog/5830.bugfix.rst new file mode 100644 index 000000000..355790fd4 --- /dev/null +++ b/changelog/5830.bugfix.rst @@ -0,0 +1 @@ +Fix fail skipping the first test in package marked as ``skip`` diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 913a93bc0..97a3ac805 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -251,18 +251,21 @@ class PyobjMixin(PyobjContext): @property def obj(self): """Underlying Python object.""" + self._mount_obj_if_needed() + return self._obj + + @obj.setter + def obj(self, value): + self._obj = value + + def _mount_obj_if_needed(self): obj = getattr(self, "_obj", None) if obj is None: self._obj = obj = self._getobj() # XXX evil hack # used to avoid Instance collector marker duplication if self._ALLOW_MARKERS: - self.own_markers.extend(get_unpacked_marks(self.obj)) - return obj - - @obj.setter - def obj(self, value): - self._obj = value + self.own_markers.extend(get_unpacked_marks(obj)) def _getobj(self): """Gets the underlying Python object. May be overwritten by subclasses.""" @@ -628,6 +631,7 @@ class Package(Module): return path in self.session._initialpaths def collect(self): + self._mount_obj_if_needed() this_path = self.fspath.dirpath() init_module = this_path.join("__init__.py") if init_module.check(file=1) and path_matches_patterns( diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 8bba479f1..371c3a4db 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1162,3 +1162,26 @@ def test_importorskip(): match="^could not import 'doesnotexist': No module named .*", ): pytest.importorskip("doesnotexist") + + +def test_skip_package(testdir): + testdir.makepyfile( + __init__=""" + import pytest + pytestmark = pytest.mark.skip + """ + ) + + testdir.makepyfile( + """ + import pytest + def test_skip1(): + assert 0 + def test_skip2(): + assert 0 + """ + ) + + result = testdir.inline_run() + _, skipped, _ = result.listoutcomes() + assert len(skipped) == 2