-1

I have set of many cases that I want to test on a single function.

Let's say:

@pytest.mark.unittest
def test_simple_test_id_odd():
    numbers = [1, 2, 3, 4, 5, 6, 7, 8]

    for number in numbers:
        assert number % 2 == 0

When I run this it stops on the first number with the error. I want the test to go all over the numbers and check each one of them.

I don't want to write a test for each number, it does not make sense, it's too long.

How can I test all the numbers and raise error for every one of them that failed?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
dasdasd
  • 1,971
  • 10
  • 45
  • 72

1 Answers1

2

In this scenario I would prefer to use pytest.mark.parametrize:

import pytest


@pytest.mark.parametrize("number", [1, 2, 3, 4, 5, 6, 7, 8])
def test_simple_test_id_odd(number):
    assert number % 2 != 0
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Robert Seaman
  • 2,432
  • 15
  • 18