-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
topic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrize
Description
I need to fail (instead of skip) tests that got empty parameters set.
My test looks like this:
def parameters_provider():
# HTTP request to some external provider service.
return service_request().result or []
@pytest.mark.parametrize("parameter", parameters_provider())
def test_something(parameter):
assert parameter is not NoneSo if provider fails to return results, test gets empty parameters set and pytest skips it, but for me this is actually error - kind of no tests run and nothing actually checked, so test must fail.
After some investigation i've found pretty nasty way to achieve my goal, in conftest.py:
def pytest_runtest_teardown(item, nextitem):
skip = item.get_marker("skip")
if skip:
reason = skip.kwargs.get("reason")
if reason.startswith("got empty parameter set"):
raise ValueError(reason)I don't like it because it depends on reason text which can change in any next pytest release. Is there any better way to do it?
funkyfuture
Metadata
Metadata
Assignees
Labels
topic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrize