The primary difference between unittest and PyTest lies in how they handle fixtures. While unittest like fixtures (setUp, tearDown, setupClass, and so on) are still supported through the TestCase class when using pytest, pytest tries to provide further decoupling of tests from fixtures.
In pytest, a fixture can be declared using the pytest.fixture decorator. Any function decorated with the decorator becomes a fixture:
@pytest.fixture
def greetings():
print("HELLO!")
yield
print("GOODBYE")
The code of the test is executed where we see the yield statement. yield in this context passes execution to the test itself. So this fixture would print "HELLO" before the test starts and then "GOODBYE" when the test finishes.
To then bind a fixture to a test, the pytest.mark.usefixtures decorator is used. So, for example, to use our new fixture with the existing TestMultiple.test_second test, we would have to decorate that test...