1 new commit in pytest: https://bitbucket.org/hpk42/pytest/commits/7a1d32a342c0/ Changeset: 7a1d32a342c0 Branch: flake8-clean User: RonnyPfannschmidt Date: 2015-02-22 16:04:31+00:00 Summary: flake8 clean testing/python Affected #: 5 files
diff -r c5689ba15d60a456526d8f4223bd575f6fc32046 -r 7a1d32a342c0433d9c30889fa04d59fbd11d3557 testing/python/collect.py --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1,4 +1,6 @@ -import pytest, py +import pytest +import py + class TestModule: def test_failing_import(self, testdir): @@ -32,6 +34,7 @@ modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',") pytest.raises(ImportError, lambda: modcol.obj) + class TestClass: def test_class_with_init_warning(self, testdir): testdir.makepyfile(""" @@ -292,15 +295,19 @@ config = testdir.parseconfigure() session = testdir.Session(config) session._fixturemanager = FixtureManager(session) + def func1(): pass + def func2(): pass - f1 = pytest.Function(name="name", parent=session, config=config, - args=(1,), callobj=func1) + f1 = pytest.Function( + name="name", parent=session, config=config, + args=(1,), callobj=func1) assert f1 == f1 - f2 = pytest.Function(name="name",config=config, - callobj=func2, parent=session) + f2 = pytest.Function( + name="name", config=config, + callobj=func2, parent=session) assert f1 != f2 def test_issue197_parametrize_emptyset(self, testdir): @@ -354,9 +361,9 @@ rec = testdir.inline_run() rec.assertoutcome(passed=2) - def test_parametrize_with_non_hashable_values_indirect(self, testdir): - """Test parametrization with non-hashable values with indirect parametrization.""" + """Test parametrization with non-hashable values + with indirect parametrization.""" testdir.makepyfile(""" archival_mapping = { '1.0': {'tag': '1.0'}, @@ -382,9 +389,9 @@ rec = testdir.inline_run() rec.assertoutcome(passed=2) - def test_parametrize_overrides_fixture(self, testdir): - """Test parametrization when parameter overrides existing fixture with same name.""" + """Test parametrization when parameter + overrides existing fixture with same name.""" testdir.makepyfile(""" import pytest @@ -400,7 +407,6 @@ rec = testdir.inline_run() rec.assertoutcome(passed=1) - def test_parametrize_with_mark(selfself, testdir): items = testdir.getitems(""" import pytest @@ -413,8 +419,12 @@ pass """) keywords = [item.keywords for item in items] - assert 'foo' in keywords[0] and 'bar' not in keywords[0] and 'baz' not in keywords[0] - assert 'foo' in keywords[1] and 'bar' in keywords[1] and 'baz' in keywords[1] + assert 'foo' in keywords[0] and \ + 'bar' not in keywords[0] and \ + 'baz' not in keywords[0] + assert 'foo' in keywords[1] and \ + 'bar' in keywords[1] and \ + 'baz' in keywords[1] def test_function_equality_with_callspec(self, testdir, tmpdir): items = testdir.getitems(""" @@ -429,9 +439,11 @@ def test_pyfunc_call(self, testdir): item = testdir.getitem("def test_func(): raise ValueError") config = item.config + class MyPlugin1: def pytest_pyfunc_call(self, pyfuncitem): raise ValueError + class MyPlugin2: def pytest_pyfunc_call(self, pyfuncitem): return True @@ -439,6 +451,7 @@ config.pluginmanager.register(MyPlugin2()) config.hook.pytest_pyfunc_call(pyfuncitem=item) + class TestSorting: def test_check_equality(self, testdir): modcol = testdir.getmodulecol(""" @@ -461,11 +474,11 @@ assert not (fn1 == fn3) assert fn1 != fn3 - for fn in fn1,fn2,fn3: + for fn in fn1, fn2, fn3: assert fn != 3 assert fn != modcol - assert fn != [1,2,3] - assert [1,2,3] != fn + assert fn != [1, 2, 3] + assert [1, 2, 3] != fn assert modcol != fn def test_allow_sane_sorting_for_decorators(self, testdir): @@ -565,11 +578,13 @@ def test_makeitem_non_underscore(self, testdir, monkeypatch): modcol = testdir.getmodulecol("def _hello(): pass") l = [] - monkeypatch.setattr(pytest.Module, 'makeitem', + monkeypatch.setattr( + pytest.Module, 'makeitem', lambda self, name, obj: l.append(name)) l = modcol.collect() assert '_hello' not in l + def test_setup_only_available_in_subdir(testdir): sub1 = testdir.mkpydir("sub1") sub2 = testdir.mkpydir("sub2") @@ -598,6 +613,7 @@ "*2 passed*" ]) + def test_modulecol_roundtrip(testdir): modcol = testdir.getmodulecol("pass", withinit=True) trail = modcol.nodeid @@ -622,13 +638,13 @@ out = result.stdout.str() assert out.find("xyz") != -1 assert out.find("conftest.py:2: ValueError") != -1 - numentries = out.count("_ _ _") # separator for traceback entries + numentries = out.count("_ _ _") # separator for traceback entries assert numentries == 0 result = testdir.runpytest("--fulltrace", p) out = result.stdout.str() assert out.find("conftest.py:2: ValueError") != -1 - numentries = out.count("_ _ _ _") # separator for traceback entries + numentries = out.count("_ _ _ _") # separator for traceback entries assert numentries > 3 def test_traceback_error_during_import(self, testdir): @@ -656,6 +672,7 @@ "E*NameError*", ]) + class TestReportInfo: def test_itemreport_reportinfo(self, testdir, linecomp): testdir.makeconftest(""" @@ -792,6 +809,7 @@ "*1 passed*", ]) + def test_customize_through_attributes(testdir): testdir.makeconftest(""" import pytest diff -r c5689ba15d60a456526d8f4223bd575f6fc32046 -r 7a1d32a342c0433d9c30889fa04d59fbd11d3557 testing/python/fixture.py --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -1,25 +1,38 @@ -import pytest, py, sys +import pytest +import py +import sys from _pytest import python as funcargs from _pytest.python import FixtureLookupError from _pytest.pytester import get_public_names from textwrap import dedent + def test_getfuncargnames(): - def f(): pass + + def f(): + pass assert not funcargs.getfuncargnames(f) - def g(arg): pass + + def g(arg): + pass assert funcargs.getfuncargnames(g) == ('arg',) - def h(arg1, arg2="hello"): pass + + def h(arg1, arg2="hello"): + pass assert funcargs.getfuncargnames(h) == ('arg1',) - def h(arg1, arg2, arg3="hello"): pass + + def h(arg1, arg2, arg3="hello"): + pass assert funcargs.getfuncargnames(h) == ('arg1', 'arg2') + class A: def f(self, arg1, arg2="hello"): pass assert funcargs.getfuncargnames(A().f) == ('arg1',) - if sys.version_info < (3,0): + if sys.version_info < (3, 0): assert funcargs.getfuncargnames(A.f) == ('arg1',) + class TestFillFixtures: def test_fillfuncargs_exposed(self): # used by oejskit, kept for compatibility @@ -33,7 +46,7 @@ def test_func(some): pass """) - result = testdir.runpytest() # "--collect-only") + result = testdir.runpytest() # "--collect-only") assert result.ret != 0 result.stdout.fnmatch_lines([ "*def test_func(some)*", @@ -361,7 +374,7 @@ assert item.funcargs["something"] == 1 assert len(get_public_names(item.funcargs)) == 2 assert "request" in item.funcargs - #assert item.funcargs == {'something': 1, "other": 2} + # assert item.funcargs == {'something': 1, "other": 2} def test_request_addfinalizer(self, testdir): item = testdir.getitem(""" @@ -412,7 +425,6 @@ mod = reprec.getcalls("pytest_runtest_setup")[0].item.module assert not mod.l - def test_request_addfinalizer_partial_setup_failure(self, testdir): p = testdir.makepyfile(""" l = [] @@ -426,7 +438,7 @@ result = testdir.runpytest(p) result.stdout.fnmatch_lines([ "*1 error*" # XXX the whole module collection fails - ]) + ]) def test_request_getmodulepath(self, testdir): modcol = testdir.getmodulecol("def test_somefunc(): pass") @@ -543,9 +555,10 @@ reprec = testdir.inline_run() reprec.assertoutcome(passed=2) + class TestRequestMarking: def test_applymarker(self, testdir): - item1,item2 = testdir.getitems(""" + item1, item2 = testdir.getitems(""" def pytest_funcarg__something(request): pass class TestClass: @@ -600,6 +613,7 @@ reprec = testdir.inline_run() reprec.assertoutcome(passed=2) + class TestRequestCachedSetup: def test_request_cachedsetup_defaultmodule(self, testdir): reprec = testdir.inline_runsource(""" @@ -638,6 +652,7 @@ item1 = testdir.getitem("def test_func(): pass") req1 = funcargs.FixtureRequest(item1) l = ["hello", "world"] + def setup(): return l.pop() ret1 = req1.cached_setup(setup, extrakey=1) @@ -653,8 +668,10 @@ item1 = testdir.getitem("def test_func(): pass") req1 = funcargs.FixtureRequest(item1) l = [] + def setup(): l.append("setup") + def teardown(val): l.append("teardown") req1.cached_setup(setup, teardown, scope="function") @@ -742,6 +759,7 @@ "*ZeroDivisionError*", ]) + class TestFixtureUsages: def test_noargfixturedec(self, testdir): testdir.makepyfile(""" @@ -962,7 +980,7 @@ reprec = testdir.inline_run("-v") reprec.assertoutcome(passed=4) l = reprec.getcalls("pytest_runtest_call")[0].item.module.l - assert l == [1,2, 10,20] + assert l == [1, 2, 10, 20] class TestFixtureManagerParseFactories: @@ -1248,8 +1266,6 @@ reprec = testdir.inline_run() reprec.assertoutcome(passed=2) - - def test_funcarg_and_setup(self, testdir): testdir.makepyfile(""" import pytest @@ -1355,7 +1371,7 @@ def test_2(self): pass """) - reprec = testdir.inline_run("-v","-s") + reprec = testdir.inline_run("-v", "-s") reprec.assertoutcome(passed=8) config = reprec.getcalls("pytest_unconfigure")[0].config l = config._conftest.getconftestmodules(p)[0].l @@ -1393,7 +1409,8 @@ @pytest.fixture(scope="class", autouse=True) def addteardown(self, item, request): l.append("setup-%d" % item) - request.addfinalizer(lambda: l.append("teardown-%d" % item)) + request.addfinalizer( + lambda: l.append("teardown-%d" % item)) def test_step1(self, item): l.append("step1-%d" % item) def test_step2(self, item): @@ -1425,9 +1442,10 @@ reprec.assertoutcome(passed=1) @pytest.mark.issue226 - @pytest.mark.parametrize("param1", ["", "params=[1]"], ids=["p00","p01"]) - @pytest.mark.parametrize("param2", ["", "params=[1]"], ids=["p10","p11"]) - def test_ordering_dependencies_torndown_first(self, testdir, param1, param2): + @pytest.mark.parametrize("param1", ["", "params=[1]"], ids=["p00", "p01"]) + @pytest.mark.parametrize("param2", ["", "params=[1]"], ids=["p10", "p11"]) + def test_ordering_dependencies_torndown_first(self, testdir, + param1, param2): testdir.makepyfile(""" import pytest l = [] @@ -1719,7 +1737,7 @@ reprec = testdir.inline_run("-v") reprec.assertoutcome(passed=4) l = reprec.getcalls("pytest_runtest_call")[0].item.module.l - assert l == [1,1,2,2] + assert l == [1, 1, 2, 2] def test_module_parametrized_ordering(self, testdir): testdir.makeconftest(""" @@ -1854,7 +1872,7 @@ 'fin:mod1', 'create:mod2', 'test2', 'create:1', 'test3', 'fin:1', 'create:2', 'test3', 'fin:2', 'create:1', 'test4', 'fin:1', 'create:2', 'test4', 'fin:2', - 'fin:mod2'] + 'fin:mod2'] import pprint pprint.pprint(list(zip(l, expected))) assert l == expected @@ -1962,7 +1980,7 @@ """) reprec = testdir.inline_run("-s") l = reprec.getcalls("pytest_runtest_call")[0].item.module.l - assert l == [1,2] + assert l == [1, 2] def test_parametrize_separated_lifecycle(self, testdir): testdir.makepyfile(""" @@ -1984,7 +2002,7 @@ l = reprec.getcalls("pytest_runtest_call")[0].item.module.l import pprint pprint.pprint(l) - #assert len(l) == 6 + # assert len(l) == 6 assert l[0] == l[1] == 1 assert l[2] == "fin1" assert l[3] == l[4] == 2 @@ -2012,7 +2030,6 @@ reprec = testdir.inline_run("-v") reprec.assertoutcome(passed=5) - @pytest.mark.issue246 @pytest.mark.parametrize("scope", ["session", "function", "module"]) def test_finalizer_order_on_parametrization(self, scope, testdir): @@ -2054,7 +2071,8 @@ l = [] @pytest.fixture(params=["John", "Doe"], scope="class") def human(request): - request.addfinalizer(lambda: l.append("fin %s" % request.param)) + request.addfinalizer( + lambda: l.append("fin %s" % request.param)) return request.param class TestGreetings: @@ -2155,7 +2173,7 @@ class TestRequestScopeAccess: - pytestmark = pytest.mark.parametrize(("scope", "ok", "error"),[ + pytestmark = pytest.mark.parametrize(("scope", "ok", "error"), [ ["session", "", "fspath class function module"], ["module", "module fspath", "cls function"], ["class", "module fspath cls", "function"], @@ -2176,7 +2194,7 @@ assert request.config def test_func(): pass - """ %(scope, ok.split(), error.split())) + """ % (scope, ok.split(), error.split())) reprec = testdir.inline_run("-l") reprec.assertoutcome(passed=1) @@ -2194,10 +2212,11 @@ assert request.config def test_func(arg): pass - """ %(scope, ok.split(), error.split())) + """ % (scope, ok.split(), error.split())) reprec = testdir.inline_run() reprec.assertoutcome(passed=1) + class TestErrors: def test_subfactory_missing_funcarg(self, testdir): testdir.makepyfile(""" @@ -2243,8 +2262,6 @@ *3 pass*2 error* """) - - def test_setupfunc_missing_funcarg(self, testdir): testdir.makepyfile(""" import pytest @@ -2262,6 +2279,7 @@ "*1 error*", ]) + class TestShowFixtures: def test_funcarg_compat(self, testdir): config = testdir.parseconfigure("--funcargs") @@ -2270,18 +2288,16 @@ def test_show_fixtures(self, testdir): result = testdir.runpytest("--fixtures") result.stdout.fnmatch_lines([ - "*tmpdir*", - "*temporary directory*", - ] - ) + "*tmpdir*", + "*temporary directory*", + ]) def test_show_fixtures_verbose(self, testdir): result = testdir.runpytest("--fixtures", "-v") result.stdout.fnmatch_lines([ - "*tmpdir*--*tmpdir.py*", - "*temporary directory*", - ] - ) + "*tmpdir*--*tmpdir.py*", + "*temporary directory*", + ]) def test_show_fixtures_testmodule(self, testdir): p = testdir.makepyfile(''' @@ -2324,7 +2340,6 @@ """) - class TestContextManagerFixtureFuncs: def test_simple(self, testdir): testdir.makepyfile(""" @@ -2419,7 +2434,6 @@ *test_yields*:2* """) - def test_no_yield(self, testdir): testdir.makepyfile(""" import pytest @@ -2450,4 +2464,3 @@ *fixture*cannot use*yield* *def arg1* """) - diff -r c5689ba15d60a456526d8f4223bd575f6fc32046 -r 7a1d32a342c0433d9c30889fa04d59fbd11d3557 testing/python/integration.py --- a/testing/python/integration.py +++ b/testing/python/integration.py @@ -2,8 +2,9 @@ from _pytest import runner from _pytest import python + class TestOEJSKITSpecials: - def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage + def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage testdir.makeconftest(""" import pytest def pytest_pycollect_makeitem(collector, name, obj): @@ -27,7 +28,7 @@ pytest._fillfuncargs(clscol) assert clscol.funcargs['arg1'] == 42 - def test_autouse_fixture(self, testdir): # rough jstests usage + def test_autouse_fixture(self, testdir): # rough jstests usage testdir.makeconftest(""" import pytest def pytest_pycollect_makeitem(collector, name, obj): @@ -59,10 +60,12 @@ def test_wrapped_getfslineno(): def func(): pass + def wrap(f): func.__wrapped__ = f func.patchings = ["qwe"] return func + @wrap def wrapped_func(x, y, z): pass @@ -70,14 +73,17 @@ fs2, lineno2 = python.getfslineno(wrap) assert lineno > lineno2, "getfslineno does not unwrap correctly" + class TestMockDecoration: def test_wrapped_getfuncargnames(self): from _pytest.python import getfuncargnames + def wrap(f): def func(): pass func.__wrapped__ = f return func + @wrap def f(x): pass @@ -86,12 +92,14 @@ def test_wrapped_getfuncargnames_patching(self): from _pytest.python import getfuncargnames + def wrap(f): def func(): pass func.__wrapped__ = f func.patchings = ["qwe"] return func + @wrap def f(x, y, z): pass @@ -159,7 +167,7 @@ reprec.assertoutcome(passed=2) calls = reprec.getcalls("pytest_runtest_logreport") funcnames = [call.report.location[2] for call in calls - if call.report.when == "call"] + if call.report.when == "call"] assert funcnames == ["T.test_hello", "test_someting"] def test_mock_sorting(self, testdir): @@ -232,6 +240,7 @@ *2 passed* """) + def test_pytestconfig_is_session_scoped(): from _pytest.python import pytestconfig assert pytestconfig._pytestfixturefunction.scope == "session" @@ -248,7 +257,7 @@ assert not reprec.getfailedcollections() calls = reprec.getreports("pytest_runtest_logreport") assert not calls - + def test_class_and_method(self, testdir): testdir.makepyfile(""" __test__ = True diff -r c5689ba15d60a456526d8f4223bd575f6fc32046 -r 7a1d32a342c0433d9c30889fa04d59fbd11d3557 testing/python/metafunc.py --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -1,6 +1,7 @@ +import py +import pytest +from _pytest import python as funcargs -import pytest, py -from _pytest import python as funcargs class TestMetafunc: def Metafunc(self, func): @@ -9,6 +10,7 @@ # initiliazation class FixtureInfo: name2fixturedefs = None + def __init__(self, names): self.names_closure = names names = funcargs.getfuncargnames(func) @@ -16,13 +18,15 @@ return funcargs.Metafunc(func, fixtureinfo, None) def test_no_funcargs(self, testdir): - def function(): pass + def function(): + pass metafunc = self.Metafunc(function) assert not metafunc.fixturenames repr(metafunc._calls) def test_function_basic(self): - def func(arg1, arg2="qwe"): pass + def func(arg1, arg2="qwe"): + pass metafunc = self.Metafunc(func) assert len(metafunc.fixturenames) == 1 assert 'arg1' in metafunc.fixturenames @@ -30,7 +34,8 @@ assert metafunc.cls is None def test_addcall_no_args(self): - def func(arg1): pass + def func(arg1): + pass metafunc = self.Metafunc(func) metafunc.addcall() assert len(metafunc._calls) == 1 @@ -39,7 +44,8 @@ assert not hasattr(call, 'param') def test_addcall_id(self): - def func(arg1): pass + def func(arg1): + pass metafunc = self.Metafunc(func) pytest.raises(ValueError, "metafunc.addcall(id=None)") @@ -52,9 +58,12 @@ assert metafunc._calls[1].id == "2" def test_addcall_param(self): - def func(arg1): pass + def func(arg1): + pass metafunc = self.Metafunc(func) - class obj: pass + + class obj: + pass metafunc.addcall(param=obj) metafunc.addcall(param=obj) metafunc.addcall(param=1) @@ -64,9 +73,12 @@ assert metafunc._calls[2].getparam("arg1") == 1 def test_addcall_funcargs(self): - def func(x): pass + def func(x): + pass metafunc = self.Metafunc(func) - class obj: pass + + class obj: + pass metafunc.addcall(funcargs={"x": 2}) metafunc.addcall(funcargs={"x": 3}) pytest.raises(pytest.fail.Exception, "metafunc.addcall({'xyz': 0})") @@ -76,38 +88,44 @@ assert not hasattr(metafunc._calls[1], 'param') def test_parametrize_error(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) - metafunc.parametrize("x", [1,2]) - pytest.raises(ValueError, lambda: metafunc.parametrize("x", [5,6])) - pytest.raises(ValueError, lambda: metafunc.parametrize("x", [5,6])) - metafunc.parametrize("y", [1,2]) - pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5,6])) - pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5,6])) + metafunc.parametrize("x", [1, 2]) + pytest.raises(ValueError, lambda: metafunc.parametrize("x", [5, 6])) + pytest.raises(ValueError, lambda: metafunc.parametrize("x", [5, 6])) + metafunc.parametrize("y", [1, 2]) + pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6])) + pytest.raises(ValueError, lambda: metafunc.parametrize("y", [5, 6])) def test_parametrize_and_id(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) - metafunc.parametrize("x", [1,2], ids=['basic', 'advanced']) + metafunc.parametrize("x", [1, 2], ids=['basic', 'advanced']) metafunc.parametrize("y", ["abc", "def"]) ids = [x.id for x in metafunc._calls] - assert ids == ["basic-abc", "basic-def", "advanced-abc", "advanced-def"] + assert ids == ["basic-abc", "basic-def", + "advanced-abc", "advanced-def"] def test_parametrize_with_wrong_number_of_ids(self, testdir): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) - pytest.raises(ValueError, lambda: - metafunc.parametrize("x", [1,2], ids=['basic'])) + with pytest.raises(ValueError): + metafunc.parametrize("x", [1, 2], ids=['basic']) - pytest.raises(ValueError, lambda: - metafunc.parametrize(("x","y"), [("abc", "def"), - ("ghi", "jkl")], ids=["one"])) + with pytest.raises(ValueError): + metafunc.parametrize(("x", "y"), [("abc", "def"), + ("ghi", "jkl")], ids=["one"]) def test_parametrize_with_userobjects(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) + class A: pass metafunc.parametrize("x", [A(), A()]) @@ -133,14 +151,15 @@ def test_idmaker_native_strings(self): from _pytest.python import idmaker - result = idmaker(("a", "b"), [(1.0, -1.1), - (2, -202), - ("three", "three hundred"), - (True, False), - (None, None), - (list("six"), [66, 66]), - (set([7]), set("seven")), - (tuple("eight"), (8, -8, 8)) + result = idmaker(("a", "b"), [ + (1.0, -1.1), + (2, -202), + ("three", "three hundred"), + (True, False), + (None, None), + (list("six"), [66, 66]), + (set([7]), set("seven")), + (tuple("eight"), (8, -8, 8)), ]) assert result == ["1.0--1.1", "2--202", @@ -154,54 +173,54 @@ @pytest.mark.issue351 def test_idmaker_idfn(self): from _pytest.python import idmaker + def ids(val): if isinstance(val, Exception): return repr(val) - result = idmaker(("a", "b"), [(10.0, IndexError()), - (20, KeyError()), - ("three", [1, 2, 3]), + result = idmaker(("a", "b"), [ + (10.0, IndexError()), + (20, KeyError()), + ("three", [1, 2, 3]), ], idfn=ids) assert result == ["10.0-IndexError()", "20-KeyError()", - "three-b2", - ] + "three-b2"] @pytest.mark.issue351 def test_idmaker_idfn_unique_names(self): from _pytest.python import idmaker + def ids(val): return 'a' - result = idmaker(("a", "b"), [(10.0, IndexError()), - (20, KeyError()), - ("three", [1, 2, 3]), + result = idmaker(("a", "b"), [ + (10.0, IndexError()), + (20, KeyError()), + ("three", [1, 2, 3]), ], idfn=ids) - assert result == ["0a-a", - "1a-a", - "2a-a", - ] + assert result == ["0a-a", "1a-a", "2a-a"] @pytest.mark.issue351 def test_idmaker_idfn_exception(self): from _pytest.python import idmaker + def ids(val): raise Exception("bad code") - result = idmaker(("a", "b"), [(10.0, IndexError()), - (20, KeyError()), - ("three", [1, 2, 3]), + result = idmaker(("a", "b"), [ + (10.0, IndexError()), + (20, KeyError()), + ("three", [1, 2, 3]), ], idfn=ids) - assert result == ["10.0-b0", - "20-b1", - "three-b2", - ] + assert result == ["10.0-b0", "20-b1", "three-b2"] def test_addcall_and_parametrize(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) metafunc.addcall({'x': 1}) - metafunc.parametrize('y', [2,3]) + metafunc.parametrize('y', [2, 3]) assert len(metafunc._calls) == 2 assert metafunc._calls[0].funcargs == {'x': 1, 'y': 2} assert metafunc._calls[1].funcargs == {'x': 1, 'y': 3} @@ -209,28 +228,30 @@ assert metafunc._calls[1].id == "0-3" def test_parametrize_indirect(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) metafunc.parametrize('x', [1], indirect=True) - metafunc.parametrize('y', [2,3], indirect=True) + metafunc.parametrize('y', [2, 3], indirect=True) metafunc.parametrize('unnamed', [1], indirect=True) assert len(metafunc._calls) == 2 assert metafunc._calls[0].funcargs == {} assert metafunc._calls[1].funcargs == {} - assert metafunc._calls[0].params == dict(x=1,y=2, unnamed=1) - assert metafunc._calls[1].params == dict(x=1,y=3, unnamed=1) + assert metafunc._calls[0].params == dict(x=1, y=2, unnamed=1) + assert metafunc._calls[1].params == dict(x=1, y=3, unnamed=1) def test_addcalls_and_parametrize_indirect(self): - def func(x, y): pass + def func(x, y): + pass metafunc = self.Metafunc(func) metafunc.addcall(param="123") metafunc.parametrize('x', [1], indirect=True) - metafunc.parametrize('y', [2,3], indirect=True) + metafunc.parametrize('y', [2, 3], indirect=True) assert len(metafunc._calls) == 2 assert metafunc._calls[0].funcargs == {} assert metafunc._calls[1].funcargs == {} - assert metafunc._calls[0].params == dict(x=1,y=2) - assert metafunc._calls[1].params == dict(x=1,y=3) + assert metafunc._calls[0].params == dict(x=1, y=2) + assert metafunc._calls[1].params == dict(x=1, y=3) def test_parametrize_functional(self, testdir): testdir.makepyfile(""" @@ -255,7 +276,7 @@ def test_parametrize_onearg(self): metafunc = self.Metafunc(lambda x: None) - metafunc.parametrize("x", [1,2]) + metafunc.parametrize("x", [1, 2]) assert len(metafunc._calls) == 2 assert metafunc._calls[0].funcargs == dict(x=1) assert metafunc._calls[0].id == "1" @@ -264,15 +285,15 @@ def test_parametrize_onearg_indirect(self): metafunc = self.Metafunc(lambda x: None) - metafunc.parametrize("x", [1,2], indirect=True) + metafunc.parametrize("x", [1, 2], indirect=True) assert metafunc._calls[0].params == dict(x=1) assert metafunc._calls[0].id == "1" assert metafunc._calls[1].params == dict(x=2) assert metafunc._calls[1].id == "2" def test_parametrize_twoargs(self): - metafunc = self.Metafunc(lambda x,y: None) - metafunc.parametrize(("x", "y"), [(1,2), (3,4)]) + metafunc = self.Metafunc(lambda x, y: None) + metafunc.parametrize(("x", "y"), [(1, 2), (3, 4)]) assert len(metafunc._calls) == 2 assert metafunc._calls[0].funcargs == dict(x=1, y=2) assert metafunc._calls[0].id == "1-2" @@ -317,7 +338,8 @@ items = scenario[1].items() argnames = [x[0] for x in items] argvalues.append(([x[1] for x in items])) - metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class") + metafunc.parametrize( + argnames, argvalues, ids=idlist, scope="class") class Test(object): scenarios = [['1', {'arg': {1: 2}, "arg2": "value2"}], @@ -344,6 +366,7 @@ *6 passed* """) + class TestMetafuncFunctional: def test_attributes(self, testdir): p = testdir.makepyfile(""" @@ -436,7 +459,6 @@ "*1 pass*", ]) - def test_generate_plugin_and_module(self, testdir): testdir.makeconftest(""" def pytest_generate_tests(metafunc): @@ -695,6 +717,7 @@ class TestMarkersWithParametrization: pytestmark = pytest.mark.issue308 + def test_simple_mark(self, testdir): s = """ import pytest @@ -843,7 +866,8 @@ @pytest.mark.parametrize(("n", "expected"), [ (1, 2), - pytest.mark.xfail("sys.version > 0", reason="some bug")((2, 3)), + pytest.mark.xfail( + "sys.version > 0", reason="some bug")((2, 3)), (3, 4), ]) def test_increment(n, expected): @@ -877,7 +901,6 @@ reprec = testdir.inline_run() reprec.assertoutcome(passed=2, skipped=2) - @pytest.mark.issue290 def test_parametrize_ID_generation_string_int_works(self, testdir): testdir.makepyfile(""" diff -r c5689ba15d60a456526d8f4223bd575f6fc32046 -r 7a1d32a342c0433d9c30889fa04d59fbd11d3557 testing/python/raises.py --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -1,5 +1,6 @@ import pytest + class TestRaises: def test_raises(self): source = "int('qwe')" @@ -29,10 +30,9 @@ def test_raises_flip_builtin_AssertionError(self): # we replace AssertionError on python level # however c code might still raise the builtin one - from _pytest.assertion.util import BuiltinAssertionError # noqa - pytest.raises(AssertionError,""" - raise BuiltinAssertionError - """) + from _pytest.assertion.util import BuiltinAssertionError + with pytest.raises(AssertionError): + raise BuiltinAssertionError() @pytest.mark.skipif('sys.version < "2.5"') def test_raises_as_contextmanager(self, testdir): Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit