Group related tests for arithmetic operations
Preconditions (2)
✅ Expected Result: All three tests run together as part of the TestArithmetic group and pass successfully
import pytest class TestArithmetic: def test_addition(self): assert 2 + 3 == 5 def test_subtraction(self): assert 5 - 2 == 3 def test_multiplication(self): assert 3 * 4 == 12
This code defines a test class TestArithmetic to group related arithmetic tests.
Each test method checks one operation using simple assert statements.
Grouping tests in a class helps organize them logically and run them together.
Running pytest on this file will discover and run all three tests, showing clear pass/fail results.
Now add a test for division inside the TestArithmetic class with inputs 10 and 2, asserting the result is 5
pytest -m "slow"?
import pytest
@pytest.mark.slow
def test_a():
assert True
@pytest.mark.fast
def test_b():
assert True
class TestGroup:
@pytest.mark.slow
def test_c(self):
assert True
def test_d(self):
assert True
TestMath?
class TestMath:
def test_add():
assert 1 + 1 == 2
def test_subtract(self):
assert 2 - 1 == 1
Pass the test and this pattern moves unknown