Skip to content

Commit

Permalink
Fix Pytest warning for pytest.raises change (#532)
Browse files Browse the repository at this point in the history
Fix these warnings seen on a test run since upgrading Pytest:

```
tests/testapp/test_cache.py::MySQLCacheTests::test_get_or_set_version
  /Users/chainz/Documents/Projects/django-mysql/tests/testapp/test_cache.py:783: PytestDeprecationWarning: The 'message' parameter is deprecated.
  (did you mean to use `match='some regex'` to check the exception message?)
  Please comment on pytest-dev/pytest#3974 if you have concerns about removal of this parameter.
    with pytest.raises(TypeError, message=msg):
  /Users/chainz/Documents/Projects/django-mysql/tests/testapp/test_cache.py:786: PytestDeprecationWarning: The 'message' parameter is deprecated.
  (did you mean to use `match='some regex'` to check the exception message?)
  Please comment on pytest-dev/pytest#3974 if you have concerns about removal of this parameter.
    with pytest.raises(TypeError, message=msg):

tests/testapp/test_models.py::FoundRowsTests::test_it_doesnt_work_with_iterator
  /Users/chainz/Documents/Projects/django-mysql/tests/testapp/test_models.py:365: PytestDeprecationWarning: The 'message' parameter is deprecated.
  (did you mean to use `match='some regex'` to check the exception message?)
  Please comment on pytest-dev/pytest#3974 if you have concerns about removal of this parameter.
    with pytest.raises(ValueError, message="doesn't work with iterator()"):
```
  • Loading branch information
jellaDolphin committed Mar 5, 2019
1 parent 320bcbd commit 2271efc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tests/testapp/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,15 @@ def my_callable():
assert cache.get_or_set('mykey', my_callable) == 'value'

def test_get_or_set_version(self):
msg = "get_or_set() missing 1 required positional argument: 'default'"
msg_re = (
r"get_or_set\(\) missing 1 required positional argument: 'default'"
)
cache.get_or_set('brian', 1979, version=2)

with pytest.raises(TypeError, message=msg):
with pytest.raises(TypeError, match=msg_re):
cache.get_or_set('brian')

with pytest.raises(TypeError, message=msg):
with pytest.raises(TypeError, match=msg_re):
cache.get_or_set('brian', version=1)

assert cache.get('brian', version=1) is None
Expand Down
3 changes: 2 additions & 1 deletion tests/testapp/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ def test_found_rows_requires_iteration(self):

def test_it_doesnt_work_with_iterator(self):
authors = Author.objects.sql_calc_found_rows()[:5]
with pytest.raises(ValueError, message="doesn't work with iterator()"):
match_re = r"doesn't work with iterator\(\)"
with pytest.raises(ValueError, match=match_re):
authors.iterator()

def test_iterator_without_it_works(self):
Expand Down

0 comments on commit 2271efc

Please sign in to comment.