A test class in pytest is a Python class that groups related test methods together. It helps organize tests logically without needing to inherit from any special base class.
Click to reveal answer
beginner
How do you name test methods inside a pytest test class?
Test methods inside a pytest test class should start with the prefix <code>test_</code>. This naming lets pytest automatically find and run them.
Click to reveal answer
intermediate
Can pytest test classes have setup and teardown methods? How?
Yes. You can define setup_method(self, method) and teardown_method(self, method) inside the test class. These run before and after each test method respectively.
Click to reveal answer
intermediate
Why use test classes instead of just functions in pytest?
Test classes help group related tests, share setup code, and improve readability. They make tests easier to maintain, especially when many tests share common setup.
Click to reveal answer
beginner
Show a simple pytest test class with two test methods and a setup method.