Beispiel #1
0
    def test_check_equality(self, pytester: Pytester) -> None:
        modcol = pytester.getmodulecol(
            """
            def test_pass(): pass
            def test_fail(): assert 0
        """
        )
        fn1 = pytester.collect_by_name(modcol, "test_pass")
        assert isinstance(fn1, pytest.Function)
        fn2 = pytester.collect_by_name(modcol, "test_pass")
        assert isinstance(fn2, pytest.Function)

        assert fn1 == fn2
        assert fn1 != modcol
        assert hash(fn1) == hash(fn2)

        fn3 = pytester.collect_by_name(modcol, "test_fail")
        assert isinstance(fn3, pytest.Function)
        assert not (fn1 == fn3)
        assert fn1 != fn3

        for fn in fn1, fn2, fn3:
            assert fn != 3  # type: ignore[comparison-overlap]
            assert fn != modcol
            assert fn != [1, 2, 3]  # type: ignore[comparison-overlap]
            assert [1, 2, 3] != fn  # type: ignore[comparison-overlap]
            assert modcol != fn
Beispiel #2
0
    def test_reportinfo_with_nasty_getattr(self, pytester: Pytester) -> None:
        # https://github.com/pytest-dev/pytest/issues/1204
        modcol = pytester.getmodulecol(
            """
            # lineno 0
            class TestClass:
                def __getattr__(self, name):
                    return "this is not an int"

                def __class_getattr__(cls, name):
                    return "this is not an int"

                def intest_foo(self):
                    pass

                def test_bar(self):
                    pass
        """
        )
        classcol = pytester.collect_by_name(modcol, "TestClass")
        assert isinstance(classcol, Class)
        path, lineno, msg = classcol.reportinfo()
        func = list(classcol.collect())[0]
        assert isinstance(func, Function)
        path, lineno, msg = func.reportinfo()
Beispiel #3
0
 def test_class_reportinfo(self, pytester: Pytester) -> None:
     modcol = pytester.getmodulecol("""
         # lineno 0
         class TestClass(object):
             def test_hello(self): pass
     """)
     classcol = pytester.collect_by_name(modcol, "TestClass")
     assert isinstance(classcol, Class)
     fspath, lineno, msg = classcol.reportinfo()
     assert str(fspath) == str(modcol.path)
     assert lineno == 1
     assert msg == "TestClass"
Beispiel #4
0
 def test_class_reportinfo(self, pytester: Pytester) -> None:
     modcol = pytester.getmodulecol("""
         # lineno 0
         class TestClass(object):
             def test_hello(self): pass
     """)
     classcol = pytester.collect_by_name(modcol, "TestClass")
     assert isinstance(classcol, Class)
     fspath, lineno, msg = classcol.reportinfo()
     with pytest.warns(DeprecationWarning):
         assert fspath == modcol.fspath
     assert lineno == 1
     assert msg == "TestClass"
Beispiel #5
0
    def test_reportinfo_with_nasty_getattr(self, pytester: Pytester) -> None:
        # https://github.com/pytest-dev/pytest/issues/1204
        modcol = pytester.getmodulecol("""
            # lineno 0
            class TestClass(object):
                def __getattr__(self, name):
                    return "this is not an int"

                def intest_foo(self):
                    pass
        """)
        classcol = pytester.collect_by_name(modcol, "TestClass")
        assert isinstance(classcol, Class)
        instance = list(classcol.collect())[0]
        assert isinstance(instance, Instance)
        fspath, lineno, msg = instance.reportinfo()