Skip to content

Commit

Permalink
Ignore socket warnings on windows for trial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jul 23, 2017
1 parent 0726d9a commit bda07d8
Showing 1 changed file with 50 additions and 55 deletions.
105 changes: 50 additions & 55 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,61 +351,12 @@ def test_func1(self):
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):
def setup_class(cls):
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):
testdir.makepyfile("""
Expand All @@ -415,7 +366,7 @@ class TC(TestCase):
def test_hello(self):
pass
""")
reprec = testdir.inline_run()
reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
reprec.assertoutcome(passed=1)
testdir.makepyfile("""
from twisted.trial.unittest import TestCase
Expand All @@ -424,7 +375,7 @@ class TC(TestCase):
def runTest(self):
pass
""")
reprec = testdir.inline_run()
reprec = testdir.inline_run(*self.ignore_unclosed_socket_warning)
reprec.assertoutcome(passed=1)

def test_trial_exceptions_with_skips(self, testdir):
Expand Down Expand Up @@ -462,7 +413,7 @@ def test_method(self):
""")
from _pytest.compat import _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([
"*XFAIL*test_trial_todo*",
"*trialselfskip*",
Expand Down Expand Up @@ -537,6 +488,50 @@ def test_hello(self):
child.expect("hellopdb")
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):
# contributed from Morten Breekevold
Expand Down

0 comments on commit bda07d8

Please sign in to comment.