Closed spumer closed 4 years ago
At fixture set up time warning is already configured, you need a imperative way to configure your warnings, I'm on mobile, so I won't find the docs links
As @RonnyPfannschmidt said, at fixture setup time pytest's own warnings were already configured, so pytest's internal warning mechanisms never has a chance of "seeing" your filter.
I suggest this (untested):
@pytest.fixture()
def raw_client(request):
return RequestsClient()
def test_oauth_error(raw_client, oauth_error):
with warnings.catch_warnings():
resp = raw_client.get('https://testserver/auth/obtain-token', params={'code': '123'})
assert resp.status_code == 400, resp.json()
As @RonnyPfannschmidt said, at fixture setup time pytest's own warnings were already configured, so pytest's internal warning mechanisms never has a chance of "seeing" your filter.
I suggest this (untested):
@pytest.fixture() def raw_client(request): return RequestsClient() def test_oauth_error(raw_client, oauth_error): with warnings.catch_warnings(): resp = raw_client.get('https://testserver/auth/obtain-token', params={'code': '123'}) assert resp.status_code == 400, resp.json()
Yea, but i whant to disable warnings explicit, not for all. Your case can be rewritten by mark: https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings
And this why i expect applymark will work fine https://docs.pytest.org/en/latest/reference.html#_pytest.fixtures.FixtureRequest.applymarker
Unlocking this subject, as I have similar issue.
I have a custom pytest plugin which creates infrastructure, which I mark with @infra(name ='postgres')
. However, I want to skip tests if the creation of the infrastructure fails.
Right now I cannot do it, because if I do applymarkers
or add_marker
inside a fixture, it is already too late. Is there a way to do it?
I whant to manage filterwarnings from shared fixture, for example filter
urllib3.exceptions.InsecureRequestWarning
when requests client fixture used.Example:
Above usage not worked for me, but filtering through pytest.ini works fine: