gpt-3.5-turbo-0125· openai
from WildChat-4.8M
how to implement pytest.mark for two conditions
- User
how to implement pytest.mark for two conditions
- Assistant
To implement pytest.mark for two conditions, you can use the
pytest.mark.parametrizedecorator along with test functions.Here's an example implementation:
pythonimport pytest @pytest.mark.parametrize("input_value, expected_output", [ (1, True), (2, False), (3, True), (4, False) ]) def test_is_odd_number(input_value, expected_output): assert input_value % 2 != 0 == expected_output @pytest.mark.parametrize("input_value, expected_output", [ (5, True), (6, False), (7, True), (8, False) ]) def test_is_prime_number(input_value, expected_output): if input_value < 2: assert False == expected_output for i in range(2, int(input_value ** 0.5) + 1): if input_value % i == 0: assert False == expected_output assert True == expected_outputIn this example, we have two test functions
test_is_odd_numberandtest_is_prime_number, and each function is parameterized with input values and expected outputs usingpytest.mark.parametrize. The test functions will be run for each combination of input value and expected output specified in the parameterized decorator.