Merge branch 'fix-flake8-issues'

This commit is contained in:
Bruno Oliveira
2017-07-19 17:03:36 -03:00
80 changed files with 1549 additions and 1082 deletions

View File

@@ -7,17 +7,22 @@ from _pytest.pytester import get_public_names
from _pytest.fixtures import FixtureLookupError
from _pytest import fixtures
def test_getfuncargnames():
def f(): pass
def f():
pass
assert not fixtures.getfuncargnames(f)
def g(arg): pass
def g(arg):
pass
assert fixtures.getfuncargnames(g) == ('arg',)
def h(arg1, arg2="hello"): pass
def h(arg1, arg2="hello"):
pass
assert fixtures.getfuncargnames(h) == ('arg1',)
def h(arg1, arg2, arg3="hello"): pass
def h(arg1, arg2, arg3="hello"):
pass
assert fixtures.getfuncargnames(h) == ('arg1', 'arg2')
class A(object):
@@ -25,9 +30,10 @@ def test_getfuncargnames():
pass
assert fixtures.getfuncargnames(A().f) == ('arg1',)
if sys.version_info < (3,0):
if sys.version_info < (3, 0):
assert fixtures.getfuncargnames(A.f) == ('arg1',)
class TestFillFixtures(object):
def test_fillfuncargs_exposed(self):
# used by oejskit, kept for compatibility
@@ -44,7 +50,7 @@ class TestFillFixtures(object):
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)*",
@@ -439,7 +445,6 @@ class TestFillFixtures(object):
])
assert "INTERNAL" not in result.stdout.str()
def test_fixture_excinfo_leak(self, testdir):
# on python2 sys.excinfo would leak into fixture executions
testdir.makepyfile("""
@@ -551,7 +556,8 @@ class TestRequestBasic(object):
else:
# see #1830 for a cleaner way to accomplish this
@contextlib.contextmanager
def expecting_no_warning(): yield
def expecting_no_warning():
yield
warning_expectation = expecting_no_warning()
@@ -639,7 +645,6 @@ class TestRequestBasic(object):
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("""
import pytest
@@ -655,7 +660,7 @@ class TestRequestBasic(object):
result = testdir.runpytest(p)
result.stdout.fnmatch_lines([
"*1 error*" # XXX the whole module collection fails
])
])
def test_request_subrequest_addfinalizer_exceptions(self, testdir):
"""
@@ -815,9 +820,10 @@ class TestRequestBasic(object):
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
class TestRequestMarking(object):
def test_applymarker(self, testdir):
item1,item2 = testdir.getitems("""
item1, item2 = testdir.getitems("""
import pytest
@pytest.fixture
@@ -875,6 +881,7 @@ class TestRequestMarking(object):
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
class TestRequestCachedSetup(object):
def test_request_cachedsetup_defaultmodule(self, testdir):
reprec = testdir.inline_runsource("""
@@ -1040,6 +1047,7 @@ class TestRequestCachedSetup(object):
"*ZeroDivisionError*",
])
class TestFixtureUsages(object):
def test_noargfixturedec(self, testdir):
testdir.makepyfile("""
@@ -1297,7 +1305,7 @@ class TestFixtureUsages(object):
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(object):
@@ -1598,8 +1606,6 @@ class TestAutouseManagement(object):
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
def test_funcarg_and_setup(self, testdir):
testdir.makepyfile("""
import pytest
@@ -1706,7 +1712,7 @@ class TestAutouseManagement(object):
pass
""")
confcut = "--confcutdir={0}".format(testdir.tmpdir)
reprec = testdir.inline_run("-v","-s", confcut)
reprec = testdir.inline_run("-v", "-s", confcut)
reprec.assertoutcome(passed=8)
config = reprec.getcalls("pytest_unconfigure")[0].config
l = config.pluginmanager._getconftestmodules(p)[0].l
@@ -1776,8 +1782,8 @@ class TestAutouseManagement(object):
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"])
@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
@@ -2108,7 +2114,7 @@ class TestFixtureMarker(object):
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("""
@@ -2243,7 +2249,7 @@ class TestFixtureMarker(object):
'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
@@ -2351,7 +2357,7 @@ class TestFixtureMarker(object):
""")
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("""
@@ -2373,7 +2379,7 @@ class TestFixtureMarker(object):
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
@@ -2401,7 +2407,6 @@ class TestFixtureMarker(object):
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):
@@ -2544,7 +2549,7 @@ class TestFixtureMarker(object):
class TestRequestScopeAccess(object):
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"],
@@ -2565,7 +2570,7 @@ class TestRequestScopeAccess(object):
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)
@@ -2583,10 +2588,11 @@ class TestRequestScopeAccess(object):
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(object):
def test_subfactory_missing_funcarg(self, testdir):
testdir.makepyfile("""
@@ -2632,8 +2638,6 @@ class TestErrors(object):
*3 pass*2 error*
""")
def test_setupfunc_missing_funcarg(self, testdir):
testdir.makepyfile("""
import pytest
@@ -2651,6 +2655,7 @@ class TestErrors(object):
"*1 error*",
])
class TestShowFixtures(object):
def test_funcarg_compat(self, testdir):
config = testdir.parseconfigure("--funcargs")
@@ -2659,18 +2664,16 @@ class TestShowFixtures(object):
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('''
@@ -2799,7 +2802,6 @@ class TestShowFixtures(object):
indented line
"""))
def test_show_fixtures_different_files(self, testdir):
"""
#833: --fixtures only shows fixtures from first file
@@ -2978,6 +2980,7 @@ class TestContextManagerFixtureFuncs(object):
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("*mew*")
class TestParameterizedSubRequest(object):
def test_call_from_fixture(self, testdir):
testfile = testdir.makepyfile("""
@@ -3083,6 +3086,3 @@ class TestParameterizedSubRequest(object):
E*{1}:5
*1 failed*
""".format(fixfile.strpath, testfile.basename))