Ignore socket warnings on windows for trial tests

This commit is contained in:
Bruno Oliveira 2017-07-22 15:04:05 -03:00
parent 0726d9a09f
commit bda07d8b27
1 changed files with 50 additions and 55 deletions

View File

@ -351,61 +351,12 @@ def test_module_level_pytestmark(testdir):
reprec.assertoutcome(skipped=1) reprec.assertoutcome(skipped=1)
def test_trial_testcase_skip_property(testdir):
pytest.importorskip('twisted.trial.unittest')
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
skip = 'dont run'
def test_func(self):
pass
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testfunction_skip_property(testdir):
pytest.importorskip('twisted.trial.unittest')
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
def test_func(self):
pass
test_func.skip = 'dont run'
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testcase_todo_property(testdir):
pytest.importorskip('twisted.trial.unittest')
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
todo = 'dont run'
def test_func(self):
assert 0
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testfunction_todo_property(testdir):
pytest.importorskip('twisted.trial.unittest')
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
def test_func(self):
assert 0
test_func.todo = 'dont run'
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
class TestTrialUnittest(object): class TestTrialUnittest(object):
def setup_class(cls): def setup_class(cls):
cls.ut = pytest.importorskip("twisted.trial.unittest") cls.ut = pytest.importorskip("twisted.trial.unittest")
# on windows trial uses a socket for a reactor and apparently doesn't close it properly
# https://twistedmatrix.com/trac/ticket/9227
cls.ignore_unclosed_socket_warning = ('-W', 'always')
def test_trial_testcase_runtest_not_collected(self, testdir): def test_trial_testcase_runtest_not_collected(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
@ -415,7 +366,7 @@ class TestTrialUnittest(object):
def test_hello(self): def test_hello(self):
pass pass
""") """)
reprec = testdir.inline_run() reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
testdir.makepyfile(""" testdir.makepyfile("""
from twisted.trial.unittest import TestCase from twisted.trial.unittest import TestCase
@ -424,7 +375,7 @@ class TestTrialUnittest(object):
def runTest(self): def runTest(self):
pass pass
""") """)
reprec = testdir.inline_run() reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
def test_trial_exceptions_with_skips(self, testdir): def test_trial_exceptions_with_skips(self, testdir):
@ -462,7 +413,7 @@ class TestTrialUnittest(object):
""") """)
from _pytest.compat import _is_unittest_unexpected_success_a_failure from _pytest.compat import _is_unittest_unexpected_success_a_failure
should_fail = _is_unittest_unexpected_success_a_failure() should_fail = _is_unittest_unexpected_success_a_failure()
result = testdir.runpytest("-rxs") result = testdir.runpytest("-rxs", *self.ignore_unclosed_socket_warning)
result.stdout.fnmatch_lines_random([ result.stdout.fnmatch_lines_random([
"*XFAIL*test_trial_todo*", "*XFAIL*test_trial_todo*",
"*trialselfskip*", "*trialselfskip*",
@ -537,6 +488,50 @@ class TestTrialUnittest(object):
child.expect("hellopdb") child.expect("hellopdb")
child.sendeof() child.sendeof()
def test_trial_testcase_skip_property(self, testdir):
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
skip = 'dont run'
def test_func(self):
pass
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testfunction_skip_property(self, testdir):
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
def test_func(self):
pass
test_func.skip = 'dont run'
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testcase_todo_property(self, testdir):
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
todo = 'dont run'
def test_func(self):
assert 0
""")
reprec = testdir.inline_run(testpath, "-s")
reprec.assertoutcome(skipped=1)
def test_trial_testfunction_todo_property(self, testdir):
testpath = testdir.makepyfile("""
from twisted.trial import unittest
class MyTestCase(unittest.TestCase):
def test_func(self):
assert 0
test_func.todo = 'dont run'
""")
reprec = testdir.inline_run(testpath, "-s", *self.ignore_unclosed_socket_warning)
reprec.assertoutcome(skipped=1)
def test_djangolike_testcase(testdir): def test_djangolike_testcase(testdir):
# contributed from Morten Breekevold # contributed from Morten Breekevold