|
58 | 58 | from _pytest.config.argparsing import Parser |
59 | 59 | from _pytest.deprecated import check_ispytest |
60 | 60 | from _pytest.deprecated import FSCOLLECTOR_GETHOOKPROXY_ISINITPATH |
| 61 | +from _pytest.deprecated import INSTANCE_COLLECTOR |
61 | 62 | from _pytest.fixtures import FuncFixtureInfo |
62 | 63 | from _pytest.main import Session |
63 | 64 | from _pytest.mark import MARK_GEN |
@@ -868,14 +869,24 @@ def xunit_setup_method_fixture(self, request) -> Generator[None, None, None]: |
868 | 869 | self.obj.__pytest_setup_method = xunit_setup_method_fixture |
869 | 870 |
|
870 | 871 |
|
871 | | -# Instance used to be a node type between Class and Function. It has been |
872 | | -# removed in pytest 7.0. Some plugins exist which reference `pytest.Instance` |
873 | | -# only to ignore it; this dummy class keeps them working. This could probably |
874 | | -# be removed at some point. |
875 | | -class Instance: |
| 872 | +class InstanceDummy: |
| 873 | + """Instance used to be a node type between Class and Function. It has been |
| 874 | + removed in pytest 7.0. Some plugins exist which reference `pytest.Instance` |
| 875 | + only to ignore it; this dummy class keeps them working. This will be removed |
| 876 | + in pytest 8.""" |
| 877 | + |
876 | 878 | pass |
877 | 879 |
|
878 | 880 |
|
| 881 | +# Note: module __getattr__ only works on Python>=3.7. Unfortunately |
| 882 | +# we can't provide this deprecation warning on Python 3.6. |
| 883 | +def __getattr__(name: str) -> object: |
| 884 | + if name == "Instance": |
| 885 | + warnings.warn(INSTANCE_COLLECTOR, 2) |
| 886 | + return InstanceDummy |
| 887 | + raise AttributeError(f"module {__name__} has no attribute {name}") |
| 888 | + |
| 889 | + |
879 | 890 | def hasinit(obj: object) -> bool: |
880 | 891 | init: object = getattr(obj, "__init__", None) |
881 | 892 | if init: |
|
0 commit comments