Skip to content

Commit 309152d

Browse files
authored
Merge pull request #2599 from nicoddemus/turn-warnings-into-errors
Turn warnings into errors WIP, waiting #2598
2 parents 1b732fe + d5bb200 commit 309152d

10 files changed

+85
-95
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ env:
1111
- TOXENV=coveralls
1212
# note: please use "tox --listenvs" to populate the build matrix below
1313
- TOXENV=linting
14-
- TOXENV=py26
1514
- TOXENV=py27
16-
- TOXENV=py33
1715
- TOXENV=py34
1816
- TOXENV=py35
19-
- TOXENV=pypy
2017
- TOXENV=py27-pexpect
2118
- TOXENV=py27-xdist
2219
- TOXENV=py27-trial
@@ -32,6 +29,12 @@ env:
3229

3330
matrix:
3431
include:
32+
- env: TOXENV=py26
33+
python: '2.6'
34+
- env: TOXENV=py33
35+
python: '3.3'
36+
- env: TOXENV=pypy
37+
python: 'pypy-5.4'
3538
- env: TOXENV=py36
3639
python: '3.6'
3740
- env: TOXENV=py37

changelog/2588.trivial

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Turn warnings into errors in pytest's own test suite in order to catch regressions due to deprecations more promptly.

testing/python/collect.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
)
1313

1414

15+
ignore_parametrized_marks = pytest.mark.filterwarnings('ignore:Applying marks directly to parameters')
16+
17+
1518
class TestModule(object):
1619
def test_failing_import(self, testdir):
1720
modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
@@ -567,7 +570,8 @@ def test_overridden_via_param(value):
567570
rec = testdir.inline_run()
568571
rec.assertoutcome(passed=1)
569572

570-
def test_parametrize_with_mark(selfself, testdir):
573+
@ignore_parametrized_marks
574+
def test_parametrize_with_mark(self, testdir):
571575
items = testdir.getitems("""
572576
import pytest
573577
@pytest.mark.foo
@@ -640,6 +644,7 @@ def test2(self, x, y):
640644
assert colitems[2].name == 'test2[a-c]'
641645
assert colitems[3].name == 'test2[b-c]'
642646

647+
@ignore_parametrized_marks
643648
def test_parametrize_skipif(self, testdir):
644649
testdir.makepyfile("""
645650
import pytest
@@ -653,6 +658,7 @@ def test_skip_if(x):
653658
result = testdir.runpytest()
654659
result.stdout.fnmatch_lines('* 2 passed, 1 skipped in *')
655660

661+
@ignore_parametrized_marks
656662
def test_parametrize_skip(self, testdir):
657663
testdir.makepyfile("""
658664
import pytest
@@ -666,6 +672,7 @@ def test_skip(x):
666672
result = testdir.runpytest()
667673
result.stdout.fnmatch_lines('* 2 passed, 1 skipped in *')
668674

675+
@ignore_parametrized_marks
669676
def test_parametrize_skipif_no_skip(self, testdir):
670677
testdir.makepyfile("""
671678
import pytest
@@ -679,6 +686,7 @@ def test_skipif_no_skip(x):
679686
result = testdir.runpytest()
680687
result.stdout.fnmatch_lines('* 1 failed, 2 passed in *')
681688

689+
@ignore_parametrized_marks
682690
def test_parametrize_xfail(self, testdir):
683691
testdir.makepyfile("""
684692
import pytest
@@ -692,6 +700,7 @@ def test_xfail(x):
692700
result = testdir.runpytest()
693701
result.stdout.fnmatch_lines('* 2 passed, 1 xfailed in *')
694702

703+
@ignore_parametrized_marks
695704
def test_parametrize_passed(self, testdir):
696705
testdir.makepyfile("""
697706
import pytest
@@ -705,6 +714,7 @@ def test_xfail(x):
705714
result = testdir.runpytest()
706715
result.stdout.fnmatch_lines('* 2 passed, 1 xpassed in *')
707716

717+
@ignore_parametrized_marks
708718
def test_parametrize_xfail_passed(self, testdir):
709719
testdir.makepyfile("""
710720
import pytest

testing/python/metafunc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,9 @@ def pytest_generate_tests(metafunc):
12891289
assert output.count('preparing foo-3') == 1
12901290

12911291

1292+
@pytest.mark.filterwarnings('ignore:Applying marks directly to parameters')
1293+
@pytest.mark.issue308
12921294
class TestMarkersWithParametrization(object):
1293-
pytestmark = pytest.mark.issue308
12941295

12951296
def test_simple_mark(self, testdir):
12961297
s = """

testing/python/setup_only.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def dynamically_requested_fixture():
187187
pass
188188
@pytest.fixture()
189189
def dependent_fixture(request):
190-
request.getfuncargvalue('dynamically_requested_fixture')
190+
request.getfixturevalue('dynamically_requested_fixture')
191191
def test_dyn(dependent_fixture):
192192
pass
193193
''')

testing/test_mark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def assert_test_is_not_selected(keyword):
787787
marks=[pytest.mark.xfail, pytest.mark.skip], id=None)),
788788
789789
])
790+
@pytest.mark.filterwarnings('ignore')
790791
def test_parameterset_extractfrom(argval, expected):
791792
extracted = ParameterSet.extract_from(argval)
792793
assert extracted == expected

testing/test_recwarn.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import warnings
33
import re
44
import py
5-
import sys
65

76
import pytest
87
from _pytest.recwarn import WarningsRecorder
@@ -125,6 +124,7 @@ def f():
125124
@pytest.mark.parametrize('warning_type', [PendingDeprecationWarning, DeprecationWarning])
126125
@pytest.mark.parametrize('mode', ['context_manager', 'call'])
127126
@pytest.mark.parametrize('call_f_first', [True, False])
127+
@pytest.mark.filterwarnings('ignore')
128128
def test_deprecated_call_modes(self, warning_type, mode, call_f_first):
129129
"""Ensure deprecated_call() captures a deprecation warning as expected inside its
130130
block/function.
@@ -170,32 +170,6 @@ def f():
170170
with pytest.deprecated_call():
171171
f()
172172

173-
def test_deprecated_function_already_called(self, testdir):
174-
"""deprecated_call should be able to catch a call to a deprecated
175-
function even if that function has already been called in the same
176-
module. See #1190.
177-
"""
178-
testdir.makepyfile("""
179-
import warnings
180-
import pytest
181-
182-
def deprecated_function():
183-
warnings.warn("deprecated", DeprecationWarning)
184-
185-
def test_one():
186-
deprecated_function()
187-
188-
def test_two():
189-
pytest.deprecated_call(deprecated_function)
190-
""")
191-
result = testdir.runpytest()
192-
# for some reason in py26 catch_warnings manages to catch the deprecation warning
193-
# from deprecated_function(), even with default filters active (which ignore deprecation
194-
# warnings)
195-
py26 = sys.version_info[:2] == (2, 6)
196-
expected = '*=== 2 passed in *===' if not py26 else '*=== 2 passed, 1 warnings in *==='
197-
result.stdout.fnmatch_lines(expected)
198-
199173

200174
class TestWarns(object):
201175
def test_strings(self):

testing/test_unittest.py

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def test_simple_unittest(testdir):
99
import unittest
1010
class MyTestCase(unittest.TestCase):
1111
def testpassing(self):
12-
self.assertEquals('foo', 'foo')
12+
self.assertEqual('foo', 'foo')
1313
def test_failing(self):
14-
self.assertEquals('foo', 'bar')
14+
self.assertEqual('foo', 'bar')
1515
""")
1616
reprec = testdir.inline_run(testpath)
1717
assert reprec.matchreport("testpassing").passed
@@ -23,10 +23,10 @@ def test_runTest_method(testdir):
2323
import unittest
2424
class MyTestCaseWithRunTest(unittest.TestCase):
2525
def runTest(self):
26-
self.assertEquals('foo', 'foo')
26+
self.assertEqual('foo', 'foo')
2727
class MyTestCaseWithoutRunTest(unittest.TestCase):
2828
def runTest(self):
29-
self.assertEquals('foo', 'foo')
29+
self.assertEqual('foo', 'foo')
3030
def test_something(self):
3131
pass
3232
""")
@@ -59,7 +59,7 @@ def setUp(self):
5959
def setup_method(self, method):
6060
self.foo2 = 1
6161
def test_both(self):
62-
self.assertEquals(1, self.foo)
62+
self.assertEqual(1, self.foo)
6363
assert self.foo2 == 1
6464
def teardown_method(self, method):
6565
assert 0, "42"
@@ -136,7 +136,7 @@ def tearDown(self):
136136
self.l.append(None)
137137
class Second(unittest.TestCase):
138138
def test_check(self):
139-
self.assertEquals(MyTestCase.l, [None])
139+
self.assertEqual(MyTestCase.l, [None])
140140
""")
141141
reprec = testdir.inline_run(testpath)
142142
passed, skipped, failed = reprec.countoutcomes()
@@ -351,61 +351,12 @@ def test_func1(self):
351351
reprec.assertoutcome(skipped=1)
352352

353353

354-
def test_trial_testcase_skip_property(testdir):
355-
pytest.importorskip('twisted.trial.unittest')
356-
testpath = testdir.makepyfile("""
357-
from twisted.trial import unittest
358-
class MyTestCase(unittest.TestCase):
359-
skip = 'dont run'
360-
def test_func(self):
361-
pass
362-
""")
363-
reprec = testdir.inline_run(testpath, "-s")
364-
reprec.assertoutcome(skipped=1)
365-
366-
367-
def test_trial_testfunction_skip_property(testdir):
368-
pytest.importorskip('twisted.trial.unittest')
369-
testpath = testdir.makepyfile("""
370-
from twisted.trial import unittest
371-
class MyTestCase(unittest.TestCase):
372-
def test_func(self):
373-
pass
374-
test_func.skip = 'dont run'
375-
""")
376-
reprec = testdir.inline_run(testpath, "-s")
377-
reprec.assertoutcome(skipped=1)
378-
379-
380-
def test_trial_testcase_todo_property(testdir):
381-
pytest.importorskip('twisted.trial.unittest')
382-
testpath = testdir.makepyfile("""
383-
from twisted.trial import unittest
384-
class MyTestCase(unittest.TestCase):
385-
todo = 'dont run'
386-
def test_func(self):
387-
assert 0
388-
""")
389-
reprec = testdir.inline_run(testpath, "-s")
390-
reprec.assertoutcome(skipped=1)
391-
392-
393-
def test_trial_testfunction_todo_property(testdir):
394-
pytest.importorskip('twisted.trial.unittest')
395-
testpath = testdir.makepyfile("""
396-
from twisted.trial import unittest
397-
class MyTestCase(unittest.TestCase):
398-
def test_func(self):
399-
assert 0
400-
test_func.todo = 'dont run'
401-
""")
402-
reprec = testdir.inline_run(testpath, "-s")
403-
reprec.assertoutcome(skipped=1)
404-
405-
406354
class TestTrialUnittest(object):
407355
def setup_class(cls):
408356
cls.ut = pytest.importorskip("twisted.trial.unittest")
357+
# on windows trial uses a socket for a reactor and apparently doesn't close it properly
358+
# https://twistedmatrix.com/trac/ticket/9227
359+
cls.ignore_unclosed_socket_warning = ('-W', 'always')
409360

410361
def test_trial_testcase_runtest_not_collected(self, testdir):
411362
testdir.makepyfile("""
@@ -415,7 +366,7 @@ class TC(TestCase):
415366
def test_hello(self):
416367
pass
417368
""")
418-
reprec = testdir.inline_run()
369+
reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
419370
reprec.assertoutcome(passed=1)
420371
testdir.makepyfile("""
421372
from twisted.trial.unittest import TestCase
@@ -424,7 +375,7 @@ class TC(TestCase):
424375
def runTest(self):
425376
pass
426377
""")
427-
reprec = testdir.inline_run()
378+
reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
428379
reprec.assertoutcome(passed=1)
429380

430381
def test_trial_exceptions_with_skips(self, testdir):
@@ -462,7 +413,7 @@ def test_method(self):
462413
""")
463414
from _pytest.compat import _is_unittest_unexpected_success_a_failure
464415
should_fail = _is_unittest_unexpected_success_a_failure()
465-
result = testdir.runpytest("-rxs")
416+
result = testdir.runpytest("-rxs", *self.ignore_unclosed_socket_warning)
466417
result.stdout.fnmatch_lines_random([
467418
"*XFAIL*test_trial_todo*",
468419
"*trialselfskip*",
@@ -537,6 +488,50 @@ def test_hello(self):
537488
child.expect("hellopdb")
538489
child.sendeof()
539490

491+
def test_trial_testcase_skip_property(self, testdir):
492+
testpath = testdir.makepyfile("""
493+
from twisted.trial import unittest
494+
class MyTestCase(unittest.TestCase):
495+
skip = 'dont run'
496+
def test_func(self):
497+
pass
498+
""")
499+
reprec = testdir.inline_run(testpath, "-s")
500+
reprec.assertoutcome(skipped=1)
501+
502+
def test_trial_testfunction_skip_property(self, testdir):
503+
testpath = testdir.makepyfile("""
504+
from twisted.trial import unittest
505+
class MyTestCase(unittest.TestCase):
506+
def test_func(self):
507+
pass
508+
test_func.skip = 'dont run'
509+
""")
510+
reprec = testdir.inline_run(testpath, "-s")
511+
reprec.assertoutcome(skipped=1)
512+
513+
def test_trial_testcase_todo_property(self, testdir):
514+
testpath = testdir.makepyfile("""
515+
from twisted.trial import unittest
516+
class MyTestCase(unittest.TestCase):
517+
todo = 'dont run'
518+
def test_func(self):
519+
assert 0
520+
""")
521+
reprec = testdir.inline_run(testpath, "-s")
522+
reprec.assertoutcome(skipped=1)
523+
524+
def test_trial_testfunction_todo_property(self, testdir):
525+
testpath = testdir.makepyfile("""
526+
from twisted.trial import unittest
527+
class MyTestCase(unittest.TestCase):
528+
def test_func(self):
529+
assert 0
530+
test_func.todo = 'dont run'
531+
""")
532+
reprec = testdir.inline_run(testpath, "-s", *self.ignore_unclosed_socket_warning)
533+
reprec.assertoutcome(skipped=1)
534+
540535

541536
def test_djangolike_testcase(testdir):
542537
# contributed from Morten Breekevold
@@ -598,7 +593,7 @@ def test_unittest_not_shown_in_traceback(testdir):
598593
class t(unittest.TestCase):
599594
def test_hello(self):
600595
x = 3
601-
self.assertEquals(x, 4)
596+
self.assertEqual(x, 4)
602597
""")
603598
res = testdir.runpytest()
604599
assert "failUnlessEqual" not in res.stdout.str()

testing/test_warnings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_func():
3333
})
3434

3535

36+
@pytest.mark.filterwarnings('always')
3637
def test_normal_flow(testdir, pyfile_with_warnings):
3738
"""
3839
Check that the warnings section is displayed, containing test node ids followed by
@@ -54,6 +55,7 @@ def test_normal_flow(testdir, pyfile_with_warnings):
5455
assert result.stdout.str().count('test_normal_flow.py::test_func') == 1
5556

5657

58+
@pytest.mark.filterwarnings('always')
5759
def test_setup_teardown_warnings(testdir, pyfile_with_warnings):
5860
testdir.makepyfile('''
5961
import warnings
@@ -115,6 +117,7 @@ def test_ignore(testdir, pyfile_with_warnings, method):
115117

116118
@pytest.mark.skipif(sys.version_info < (3, 0),
117119
reason='warnings message is unicode is ok in python3')
120+
@pytest.mark.filterwarnings('always')
118121
def test_unicode(testdir, pyfile_with_warnings):
119122
testdir.makepyfile('''
120123
# -*- coding: utf8 -*-
@@ -152,6 +155,7 @@ def fix():
152155
warnings.warn(u"测试")
153156
yield
154157
158+
@pytest.mark.filterwarnings('always')
155159
def test_func(fix):
156160
pass
157161
''')

0 commit comments

Comments
 (0)