Complete the code to define a test class in pytest.
class TestExample: def [1](self): assert 1 + 1 == 2
The method name must start with test_ for pytest to recognize it as a test.
Complete the code to use a setup method in a pytest test class.
class TestSetup: def [1](self): self.value = 10 def test_value(self): assert self.value == 10
setup or setUp which are not recognized by pytest.setup_class which runs once per class, not before each test.In pytest, setup_method is used to run setup code before each test method.
Fix the error in the test class to correctly use a class-level setup in pytest.
class TestClassSetup: @classmethod def [1](cls): cls.data = [1, 2, 3] def test_data_length(self): assert len(self.data) == 3
setupMethod or setup.@classmethod decorator.The correct class-level setup method name in pytest is setup_class decorated with @classmethod.
Fill both blanks to correctly skip a test method conditionally in a pytest test class.
import pytest class TestSkip: @pytest.mark.[1](reason="Not ready") def [2](self): assert False
skipif without a condition.test_ prefix.The decorator @pytest.mark.skip skips the test unconditionally. The test method must start with test_.
Fill all three blanks to correctly parametrize a test method inside a pytest test class.
import pytest class TestParam: @pytest.mark.[1]("input,expected", [(1, 2), (3, 4)]) def [2](self, [3], expected): assert [3] + 1 == expected
parameterize.Use @pytest.mark.parametrize to run a test with multiple inputs. The test method must start with test_. The parameter name must match the first argument of parametrize.