Another approach is to use parametrize.
my_regex = re.compile("<this is where the magic (doesn't)? happen(s)?>")
@pytest.mark.parametrize('test_str', [
"an easy test that I'm sure will pass",
"a few things that may trip me up",
"a really pathological, contrived example",
"something from the real world?",
])
def test_my_regex(test_str):
assert my_regex.match(test_str) is not None
This will produce an independent test case for each test string. This IMO is cleaner, easier to add new cases and also has the advantage of allowing each test_str
to fail individually without affecting the others.