py.test does not find tests under a class

By convention it searches for

Test prefixed test classes (without an init method)

eg.

# content of test_class.py
class TestClass:
    def test_one(self):
        x = "this"
        assert 'h' in x

    def test_two(self):
        x = "hello"
        assert hasattr(x, 'check')

    # this works too
    @staticmethod
    def test_three():
        pass

    # this doesn't work
    #@classmethod
    #def test_three(cls):
    #    pass

See the docs:

  • Group multiple tests in a class
  • Conventions for Python test discovery

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)