[Python] How to mark one function not a test for pytest?

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using pytest to test some code based on TensorFlow.

    A TestCase is defined for simplicity like:

    class TestCase(tf.test.TestCase):
    # ...


    The problem is tf.test.TestCase provide a useful function self.test_session(), which was treated as a test method in pytest since its name starts with test_.

    The result pytest report more succeed tests than test methods I defined due to test_session() methods.

    I use the following code to skip test_session:

    class TestCase(tf.test.TestCase):
    @pytest.mark.skip
    @contextmanager
    def test_session(self):
    with super().test_session() as sess:
    yield sess


    However there would be some "s" in test report indicating there are some skip tests.

    Is there anyway I can mark one exact method not a test method without changing pytest test discovery rules globally?

    Continue reading...

Compartilhe esta Página