-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
  • 107,083
  • 22
  • 201
  • 376
dasdasd
  • 1,827
  • 10
  • 44
  • 67

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
  • 107,083
  • 22
  • 201
  • 376
Robert Seaman
  • 2,234
  • 14
  • 18