From 2700a94d4940057e94ab76747a5a4986ade88726 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 21 Nov 2013 14:40:14 +0100 Subject: [PATCH] remove an old duplicate marker and use recent pytest mechanism for parametrization --- testing/conftest.py | 22 ++++------------------ testing/test_capture.py | 6 +++--- testing/test_config.py | 2 +- testing/test_conftest.py | 2 +- testing/test_mark.py | 6 +++--- testing/test_unittest.py | 4 ++-- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/testing/conftest.py b/testing/conftest.py index b4c06e5ee..c96cb54f0 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -12,10 +12,6 @@ def pytest_addoption(parser): help=("run FD checks if lsof is available")) def pytest_configure(config): - config.addinivalue_line("markers", - "multi(arg=[value1,value2, ...]): call the test function " - "multiple times with arg=value1, then with arg=value2, ... " - ) if config.getvalue("lsof"): try: out = py.process.cmdexec("lsof -p %d" % pid) @@ -57,19 +53,6 @@ def pytest_runtest_teardown(item, __multicall__): check_open_files(item.config) return x -def pytest_generate_tests(metafunc): - multi = getattr(metafunc.function, 'multi', None) - if multi is not None: - assert len(multi.kwargs) == 1 - for name, l in multi.kwargs.items(): - for val in l: - metafunc.addcall(funcargs={name: val}) - elif 'anypython' in metafunc.fixturenames: - for name in ('python2.5', 'python2.6', - 'python2.7', 'python3.2', "python3.3", - 'pypy', 'jython'): - metafunc.addcall(id=name, param=name) - # XXX copied from execnet's conftest.py - needs to be merged winpymap = { 'python2.7': r'C:\Python27\python.exe', @@ -100,7 +83,10 @@ def getexecutable(name, cache={}): cache[name] = executable return executable -def pytest_funcarg__anypython(request): +@pytest.fixture(params=['python2.5', 'python2.6', + 'python2.7', 'python3.2', "python3.3", + 'pypy', 'jython']) +def anypython(request): name = request.param executable = getexecutable(name) if executable is None: diff --git a/testing/test_capture.py b/testing/test_capture.py index d8271806f..edba3fcb3 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -32,7 +32,7 @@ class TestCaptureManager: assert capman._getmethod(config, sub.join("test_hello.py")) == mode @needsosdup - @pytest.mark.multi(method=['no', 'fd', 'sys']) + @pytest.mark.parametrize("method", ['no', 'fd', 'sys']) def test_capturing_basic_api(self, method): capouter = py.io.StdCaptureFD() old = sys.stdout, sys.stderr, sys.stdin @@ -81,7 +81,7 @@ class TestCaptureManager: capouter.reset() @pytest.mark.xfail("hasattr(sys, 'pypy_version_info')") -@pytest.mark.multi(method=['fd', 'sys']) +@pytest.mark.parametrize("method", ['fd', 'sys']) def test_capturing_unicode(testdir, method): if sys.version_info >= (3,0): obj = "'b\u00f6y'" @@ -100,7 +100,7 @@ def test_capturing_unicode(testdir, method): "*1 passed*" ]) -@pytest.mark.multi(method=['fd', 'sys']) +@pytest.mark.parametrize("method", ['fd', 'sys']) def test_capturing_bytes_in_utf8_encoding(testdir, method): testdir.makepyfile(""" def test_unicode(): diff --git a/testing/test_config.py b/testing/test_config.py index e29a38626..e43c37aa1 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -41,7 +41,7 @@ class TestParseIni: "*tox.ini:2*requires*9.0*actual*" ]) - @pytest.mark.multi(name="setup.cfg tox.ini pytest.ini".split()) + @pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split()) def test_ini_names(self, testdir, name): testdir.tmpdir.join(name).write(py.std.textwrap.dedent(""" [pytest] diff --git a/testing/test_conftest.py b/testing/test_conftest.py index c2d5ff1c6..9b5fa94e9 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -182,7 +182,7 @@ def test_setinitial_confcut(testdir): assert conftest.getconftestmodules(sub) == [] assert conftest.getconftestmodules(conf.dirpath()) == [] -@pytest.mark.multi(name='test tests whatever .dotdir'.split()) +@pytest.mark.parametrize("name", 'test tests whatever .dotdir'.split()) def test_setinitial_conftest_subdirs(testdir, name): sub = testdir.mkdir(name) subconftest = sub.ensure("conftest.py") diff --git a/testing/test_mark.py b/testing/test_mark.py index d6a021a0b..1e292c56d 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -124,7 +124,7 @@ def test_strict_prohibits_unregistered_markers(testdir): "*unregisteredmark*not*registered*", ]) -@pytest.mark.multi(spec=[ +@pytest.mark.parametrize("spec", [ ("xyz", ("test_one",)), ("xyz and xyz2", ()), ("xyz2", ("test_two",)), @@ -147,7 +147,7 @@ def test_mark_option(spec, testdir): assert len(passed) == len(passed_result) assert list(passed) == list(passed_result) -@pytest.mark.multi(spec=[ +@pytest.mark.parametrize("spec", [ ("interface", ("test_interface",)), ("not interface", ("test_nointer",)), ]) @@ -172,7 +172,7 @@ def test_mark_option_custom(spec, testdir): assert len(passed) == len(passed_result) assert list(passed) == list(passed_result) -@pytest.mark.multi(spec=[ +@pytest.mark.parametrize("spec", [ ("interface", ("test_interface",)), ("not interface", ("test_nointer",)), ]) diff --git a/testing/test_unittest.py b/testing/test_unittest.py index 0514ad6d3..68b629705 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -236,7 +236,7 @@ def test_setup_class(testdir): reprec.assertoutcome(passed=3) -@pytest.mark.multi(type=['Error', 'Failure']) +@pytest.mark.parametrize("type", ['Error', 'Failure']) def test_testcase_adderrorandfailure_defers(testdir, type): testdir.makepyfile(""" from unittest import TestCase @@ -256,7 +256,7 @@ def test_testcase_adderrorandfailure_defers(testdir, type): result = testdir.runpytest() assert 'should not raise' not in result.stdout.str() -@pytest.mark.multi(type=['Error', 'Failure']) +@pytest.mark.parametrize("type", ['Error', 'Failure']) def test_testcase_custom_exception_info(testdir, type): testdir.makepyfile(""" from unittest import TestCase