Repository: pytest-dev/pytest
File: testing/python/collect.py (Python)

Code before:
        pytester.makepyfile(
            """
            import collections

            TestCase = collections.namedtuple('TestCase', ['a'])
        """
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(
            "*cannot collect test class 'TestCase' "
            "because it has a __new__ constructor*"
        )

    def test_issue2234_property(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            class TestCase(object):
                @property
                def prop(self):
                    raise NotImplementedError()
        """
        )
        result = pytester.runpytest()
        assert result.ret == ExitCode.NO_TESTS_COLLECTED

    def test_does_not_discover_properties(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """\
            class TestCase:
                @property
                def oops(self):
                    raise SystemExit('do not call me!')
            """
        )
        result = pytester.runpytest()
        assert result.ret == ExitCode.NO_TESTS_COLLECTED

    def test_does_not_discover_instance_descriptors(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """\
            # not `@property`, but it acts like one
            # this should cover the case of things like `@cached_property` / etc.
            class MyProperty:
                def __init__(self, func):
                    self._func = func
                def __get__(self, inst, owner):
                    if inst is None:
                        return self
                    else:
                        return self._func.__get__(inst, owner)()


Review comment (suggestion):
```suggestion
    def test_does_not_discover_properties(self, pytester: Pytester) -> None:
        """Regression test for #12446."""
```

Code after:
        pytester.makepyfile(
            """
            import collections

            TestCase = collections.namedtuple('TestCase', ['a'])
        """
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(
            "*cannot collect test class 'TestCase' "
            "because it has a __new__ constructor*"
        )

    def test_issue2234_property(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            class TestCase(object):
                @property
                def prop(self):
                    raise NotImplementedError()
        """
        )
        result = pytester.runpytest()
        assert result.ret == ExitCode.NO_TESTS_COLLECTED

    def test_does_not_discover_properties(self, pytester: Pytester) -> None:
        """Regression test for #12446."""
        pytester.makepyfile(
            """\
            class TestCase:
                @property
                def oops(self):
                    raise SystemExit('do not call me!')
            """
        )
        result = pytester.runpytest()
        assert result.ret == ExitCode.NO_TESTS_COLLECTED

    def test_does_not_discover_instance_descriptors(self, pytester: Pytester) -> None:
        """Regression test for #12446."""
        pytester.makepyfile(
            """\
            # not `@property`, but it acts like one
            # this should cover the case of things like `@cached_property` / etc.
            class MyProperty:
                def __init__(self, func):
                    self._func = func
                def __get__(self, inst, owner):
                    if inst is None:
                        return self
                    else: