From 424e5d13947c79fff2e945332df0d876670e373b Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 27 Apr 2015 15:06:47 +0200 Subject: [PATCH] make test suite more tolerable against xdist causing warnings itself (which it does currently) --HG-- branch : plugtestfix --- _pytest/pytester.py | 8 ++++++++ testing/python/collect.py | 6 +----- testing/python/metafunc.py | 4 +--- testing/test_config.py | 11 ++++------- testing/test_nose.py | 4 +--- testing/test_terminal.py | 2 +- tox.ini | 2 +- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 9bb040691..09517e8ff 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -238,6 +238,13 @@ class RunResult: 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. @@ -872,6 +879,7 @@ class LineComp: lines1 = val.split("\n") return LineMatcher(lines1).fnmatch_lines(lines2) + class LineMatcher: """Flexible matching of text. diff --git a/testing/python/collect.py b/testing/python/collect.py index eb8fad1f9..6629d0833 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -58,14 +58,10 @@ class TestClass: 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): diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index cbff9adfe..700e0a790 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -375,9 +375,7 @@ class TestMetafuncFunctional: 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(""" diff --git a/testing/test_config.py b/testing/test_config.py index 8ea23e97b..160276d93 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -368,9 +368,8 @@ class TestWarning: 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): @@ -391,15 +390,13 @@ class TestWarning: 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: diff --git a/testing/test_nose.py b/testing/test_nose.py index fac7a5d93..af878da78 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -339,9 +339,7 @@ def test_SkipTest_during_collection(testdir): 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): diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 8e273e147..61fca0b59 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -412,7 +412,7 @@ class TestTerminalFunctional: 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([ diff --git a/tox.ini b/tox.ini index 9f683c46f..682289413 100644 --- a/tox.ini +++ b/tox.ini @@ -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