<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jan 11, 2014 at 3:45 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The docs say this [1]:<br>
==============================<u></u>============================<br>
 test.support.check_warnings(*<u></u>filters, quiet=True)<br>
<br>
    A convenience wrapper for warnings.catch_warnings() that makes it easier to test that a warning was correctly raised. It is approximately equivalent to calling warnings.catch_warnings(<u></u>record=True) with warnings.simplefilter() set to always and with the option to automatically validate the results that are recorded.<br>


<br>
    check_warnings accepts 2-tuples of the form ("message regexp", WarningCategory) as positional arguments. If one or more filters are provided, or if the optional keyword argument quiet is False, it checks to make sure the warnings are as expected: each specified filter must match at least one of the warnings raised by the enclosed code or the test fails, and if any warnings are raised that do not match any of the specified filters the test fails. To disable the first of these checks, set quiet to True.<br>


==============================<u></u>============================<br>
<br>
What I want is to make sure that DeprecationWarnings are being raised:<br>
==============================<u></u>============================<br>
        with support.check_warnings(<br>
                ("automatic int conversions have been deprecated", DeprecationWarning),<br>
                quiet=False,<br>
                ):<br>
            exec("'%x' % pi")<br>
            exec("'%x' % 3.14")<br>
            exec("'%X' % 2.11")<br>
            exec("'%o' % 1.79")<br>
            exec("'%c' % pi")<br>
==============================<u></u>============================<br>
<br>
But if I throw in something that doesn't raise a deprecation warning, the test still passes:<br>
==============================<u></u>============================<br>
            exec("'%d' % 3")<br>
==============================<u></u>============================<br>
<br>
Am I doing something wrong?<br></blockquote><div><br></div><div>You're assuming the context manager is doing something magical to verify that all calls in the block raise the expected exception. What you want to do is execute it in a loop::</div>

<div><br></div><div>  for test in (...):</div><div>    with support.check_warnings(("automatic int conversions have been deprecated", DeprecationWarning), quiet=False):</div><div>      exec(test)</div></div></div>

</div>