Skip to content

Commit

Permalink
make test suite more tolerable against xdist causing warnings itself …
Browse files Browse the repository at this point in the history
…(which it does

currently)

--HG--
branch : plugtestfix
  • Loading branch information
hpk42 committed Apr 27, 2015
1 parent 2d8f115 commit 424e5d1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
8 changes: 8 additions & 0 deletions _pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ def parseoutcomes(self):
d[cat] = int(num)
return d

def assertoutcome(self, passed=0, skipped=0, failed=0):
d = self.parseoutcomes()
assert passed == d.get("passed", 0)
assert skipped == d.get("skipped", 0)
assert failed == d.get("failed", 0)


class TmpTestdir:
"""Temporary test directory with tools to test/run py.test itself.
Expand Down Expand Up @@ -872,6 +879,7 @@ def assert_contains_lines(self, lines2):
lines1 = val.split("\n")
return LineMatcher(lines1).fnmatch_lines(lines2)


class LineMatcher:
"""Flexible matching of text.
Expand Down
6 changes: 1 addition & 5 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ def test_class_with_init_warning(self, testdir):
class TestClass1:
def __init__(self):
pass
class TestClass2(object):
def __init__(self):
pass
""")
result = testdir.runpytest("-rw")
result.stdout.fnmatch_lines("""
result.stdout.fnmatch_lines_random("""
WC1*test_class_with_init_warning.py*__init__*
*2 warnings*
""")

def test_class_subclassobject(self, testdir):
Expand Down
4 changes: 1 addition & 3 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ def test_method(self, metafunc, pytestconfig):
assert metafunc.cls == TestClass
""")
result = testdir.runpytest(p, "-v")
result.stdout.fnmatch_lines([
"*2 passed in*",
])
result.assertoutcome(passed=2)

def test_addcall_with_two_funcargs_generators(self, testdir):
testdir.makeconftest("""
Expand Down
11 changes: 4 additions & 7 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ def test_warn_config(self, testdir):
def pytest_configure(config):
config.warn("C1", "hello")
def pytest_logwarning(code, message):
assert code == "C1"
assert message == "hello"
l.append(1)
if message == "hello" and code == "C1":
l.append(1)
""")
testdir.makepyfile("""
def test_proper(pytestconfig):
Expand All @@ -391,15 +390,13 @@ def test_hello(fix):
pass
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
*1 warning*
""")
assert result.parseoutcomes()["warnings"] > 0
assert "hello" not in result.stdout.str()

result = testdir.runpytest("-rw")
result.stdout.fnmatch_lines("""
===*warning summary*===
*WT1*test_warn_on_test_item*:5*hello*
*1 warning*
""")

class TestRootdir:
Expand Down
4 changes: 1 addition & 3 deletions testing/test_nose.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ def test_failing():
assert False
""")
result = testdir.runpytest(p)
outcome = result.parseoutcomes()
outcome.pop('seconds')
assert outcome == dict(skipped=1)
result.assertoutcome(skipped=1)


def test_SkipTest_in_test(testdir):
Expand Down
2 changes: 1 addition & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_passes():
py.std.sys.platform, verinfo,
py.__version__, pytest.__version__),
"*test_header_trailer_info.py .",
"=* 1 passed in *.[0-9][0-9] seconds *=",
"=* 1 passed*in *.[0-9][0-9] seconds *=",
])
if pytest.config.pluginmanager._plugin_distinfo:
result.stdout.fnmatch_lines([
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ basepython=python3.3
deps={[testenv:py27-xdist]deps}
commands=
py.test -n3 -rfsxX \
--junitxml={envlogdir}/junit-{envname}.xml testing
--junitxml={envlogdir}/junit-{envname}.xml {posargs:testing}

[testenv:py27-pexpect]
changedir=testing
Expand Down

0 comments on commit 424e5d1

Please sign in to comment.