Skip to content

Python Unit Test Basic

pytest.fixture scope

Available scopes are function, class, module, and session. The default scope is function.

Python
@pytest.fixture(scope='function')
def test_function():
    pass

Mock

  1. Mock a class with attributes

    Python
    obj = Mock(spec=Class, attr=value)