From b991a3199e7fac2f59ff546a63da874cd9b4fd37 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 2 Jul 2019 09:38:30 +1000 Subject: [PATCH] Fix test failures with pytest 5 str() behavior on pytest ExceptionInfo objects was changed in pytest 5.0.0: https://github.com/pytest-dev/pytest/issues/5412 This caused various tests to fail, as it was assumed that str() on those objects would include exception messages. Update the tests to check the exceptions instead, rather than the ExceptionInfo wrappers. --- tests/client/test_client.py | 2 +- tests/client/test_poller.py | 2 +- tests/client/test_search.py | 2 +- tests/criteria/test_criteria.py | 2 +- tests/fake/test_fake.py | 2 +- tests/repository/test_publish.py | 2 +- tests/util/test_lookup.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 1097cb81..f0e46a75 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -164,4 +164,4 @@ def test_get_missing(client, requests_mocker): repo_f.result() # It should explain the problem - assert "repo1 was not found" in str(error) + assert "repo1 was not found" in str(error.value) diff --git a/tests/client/test_poller.py b/tests/client/test_poller.py index a5c22f17..68deba5f 100644 --- a/tests/client/test_poller.py +++ b/tests/client/test_poller.py @@ -182,4 +182,4 @@ def test_retries_exhausted(requests_mocker): poller(descriptors) # It should pass through whatever was the underlying error - assert "400 Client Error" in str(exc_info) + assert "400 Client Error" in str(exc_info.value) diff --git a/tests/client/test_search.py b/tests/client/test_search.py index 851de3bc..3c5cc87a 100644 --- a/tests/client/test_search.py +++ b/tests/client/test_search.py @@ -68,4 +68,4 @@ def test_non_matcher(): with pytest.raises(TypeError) as exc_info: field_match("oops not a matcher") - assert "Not a matcher" in str(exc_info) + assert "Not a matcher" in str(exc_info.value) diff --git a/tests/criteria/test_criteria.py b/tests/criteria/test_criteria.py index 51a69dbd..e1088530 100644 --- a/tests/criteria/test_criteria.py +++ b/tests/criteria/test_criteria.py @@ -12,4 +12,4 @@ def test_field_in_str_invalid(): """ with pytest.raises(ValueError) as exc_info: Criteria.with_field_in("x", "someval") - assert "Must be an iterable: 'someval'" in str(exc_info) + assert "Must be an iterable: 'someval'" in str(exc_info.value) diff --git a/tests/fake/test_fake.py b/tests/fake/test_fake.py index a7d906d1..4097dae9 100644 --- a/tests/fake/test_fake.py +++ b/tests/fake/test_fake.py @@ -33,7 +33,7 @@ def test_get_missing_raises(): with pytest.raises(PulpException) as raised: repo_f.result() - assert "some-repo not found" in str(raised) + assert "some-repo not found" in str(raised.value) def test_get_wrong_type_raises(): diff --git a/tests/repository/test_publish.py b/tests/repository/test_publish.py index 2801e00a..1e667399 100644 --- a/tests/repository/test_publish.py +++ b/tests/repository/test_publish.py @@ -171,7 +171,7 @@ def test_publish_fail(fast_poller, requests_mocker, client): # The exception should have a reference to the task which failed assert error.value.task.id == "task1" - assert "Task task1 failed" in str(error) + assert "Task task1 failed" in str(error.value) def test_publish_broken_response(fast_poller, requests_mocker, client): diff --git a/tests/util/test_lookup.py b/tests/util/test_lookup.py index 66635e56..30e4d06d 100644 --- a/tests/util/test_lookup.py +++ b/tests/util/test_lookup.py @@ -17,7 +17,7 @@ def test_lookup_nested_absent_raise(): with pytest.raises(KeyError) as error: lookup(data, "a.b.d") - assert "a.b.d" in str(error) + assert "a.b.d" in str(error.value) def test_lookup_nested_absent_default():