diff --git a/jenkinsapi_tests/unittests/test_build.py b/jenkinsapi_tests/unittests/test_build.py index a53c439c..c5d5cc5e 100644 --- a/jenkinsapi_tests/unittests/test_build.py +++ b/jenkinsapi_tests/unittests/test_build.py @@ -1,3 +1,4 @@ +import warnings import requests import pytest import pytz @@ -258,14 +259,12 @@ def fake_get_data(cls, tree=None, params=None): monkeypatch.setattr(Build, "get_data", fake_get_data) with pytest.raises(requests.HTTPError) as excinfo: - with pytest.warns(None) as record: + with pytest.warns( + UserWarning, + match="Make sure the Environment Injector plugin is installed." + ): build.get_env_vars() assert "404" == str(excinfo.value) - assert len(record) == 1 - expected = UserWarning( - "Make sure the Environment Injector " "plugin is installed." - ) - assert str(record[0].message) == str(expected) def test_build_env_vars_other_exception(monkeypatch, build): @@ -275,10 +274,10 @@ def fake_get_data(cls, tree=None, params=None): monkeypatch.setattr(Build, "get_data", fake_get_data) with pytest.raises(Exception) as excinfo: - with pytest.warns(None) as record: + with warnings.catch_warnings(): + warnings.simplefilter("error") build.get_env_vars() assert "" == str(excinfo.value) - assert len(record) == 0 def test_build_get_status(build) -> None: