Skip to content

Commit

Permalink
Added checking for no expected warning
Browse files Browse the repository at this point in the history
Details:

* So far, when a testcase using 'simplified_test_function' did not specify
  expected warnings, warnings that occurred were tolerated..
  This change fixes that by raising an AssertionError in that case.

* Adjusted a testcase to accomodate the new check.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Oct 4, 2020
1 parent 04408b4 commit 3796d54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Released: not yet

**Enhancements:**

* Added checking for no expected warning. Adjusted a testcase to accomodate
the new check. (see issue #65)

**Cleanup:**

**Known issues:**
Expand Down
9 changes: 5 additions & 4 deletions tests/unittest/test_nocasedict.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
TESTDICT_SUPPORTS_COMPARISON = \
TEST_AGAINST_DICT and sys.version_info[0:2] == (2, 7)

# Indicates the dict being tested issues UserWarning about unordered kwargs
TESTDICT_WARNS_KWARGS = \
# Indicates the dict being tested issues UserWarning about not preserving order
# of items in kwargs or in standard dict
TESTDICT_WARNS_ORDER = \
not TEST_AGAINST_DICT and sys.version_info[0:2] < (3, 7)

# Indicates the dict supports the iter..() and view..() methods
Expand Down Expand Up @@ -177,7 +178,7 @@ def __ne__(self, other):
exp_dict=OrderedDict([('Dog', 'Cat'), ('Budgie', 'Fish')]),
verify_order=False,
),
None, None, True
None, UserWarning if TESTDICT_WARNS_ORDER else None, True
),
(
"Dict from keyword args",
Expand All @@ -187,7 +188,7 @@ def __ne__(self, other):
exp_dict=OrderedDict([('Dog', 'Cat'), ('Budgie', 'Fish')]),
verify_order=False,
),
None, UserWarning if TESTDICT_WARNS_KWARGS else None, True
None, UserWarning if TESTDICT_WARNS_ORDER else None, True
),
(
"Dict from list as positional arg and keyword args",
Expand Down
34 changes: 24 additions & 10 deletions tests/utils/simplified_test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,35 @@ def wrapper_func(desc, kwargs, exp_exc_types, exp_warn_types, condition):
ret = None # Debugging hint
assert len(rec_warnings) >= 1
else:
if exp_exc_types:
with pytest.raises(exp_exc_types):
with pytest.warns(None) as rec_warnings:
if exp_exc_types:
with pytest.raises(exp_exc_types):
if condition == 'pdb':
pdb.set_trace()

test_func(testcase, **kwargs) # expecting an exception

ret = None # Debugging hint
else:
if condition == 'pdb':
pdb.set_trace()

test_func(testcase, **kwargs) # expecting an exception

ret = None # Debugging hint
else:
if condition == 'pdb':
pdb.set_trace()
test_func(testcase, **kwargs) # not expecting an exception

test_func(testcase, **kwargs) # not expecting an exception
ret = None # Debugging hint

ret = None # Debugging hint
# Verify that no warnings have occurred
if exp_warn_types is None and rec_warnings:
lines = []
for w in rec_warnings.list:
tup = (w.filename, w.lineno, w.category.__name__,
str(w.message))
line = "{t[0]}:{t[1]}: {t[2]}: {t[3]}".format(t=tup)
if line not in lines:
lines.append(line)
msg = "Unexpected warnings:\n{}".format(
'\n'.join(lines))
raise AssertionError(msg)
return ret

# Needed because the decorator is signature-changin
Expand Down

0 comments on commit 3796d54

Please sign in to comment.