def test_addition(): assert 1 + 1 == 2 def test_subtraction(): assert 2 - 1 == 1 class TestMath: def test_multiply(self): assert 2 * 3 == 6 def helper(self): return 5
pytest will find test_addition, test_subtraction, and test_multiply inside TestMath. The method helper is ignored because it does not start with 'test_'. All three tests pass.
def func(x): if x < 0: raise ValueError("Negative value") return x
Option C uses pytest.raises context manager correctly to check for exceptions. Option C compares return value to exception class, which is incorrect. Option C is invalid syntax. Option C is unittest style, not pytest.
class math_tests: def test_divide(self): assert 10 / 2 == 5
pytest discovers test classes only if their names start with 'Test'. Here, the class is named 'math_tests' (lowercase 'm'), so pytest ignores it. The method name is correct, and the assert and division are valid.
Option D follows pytest conventions: tests in a separate 'tests' folder and files named starting with 'test_'. This helps pytest find and run tests easily. Other options reduce clarity and maintainability.
Scope='module' means the fixture runs once when the module starts and is reused by all tests in that module. This improves performance when setup is expensive. Other scopes are 'function', 'class', and 'session'.