@@ -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-
406354class 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
541536def 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 ()
0 commit comments