run black

This commit is contained in:
Ronny Pfannschmidt
2018-05-23 16:48:46 +02:00
parent 3e1590bcfc
commit 703e4b11ba
133 changed files with 13821 additions and 9370 deletions

View File

@@ -4,8 +4,10 @@ from _pytest import runner
class TestOEJSKITSpecials(object):
def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage
testdir.makeconftest("""
testdir.makeconftest(
"""
import pytest
def pytest_pycollect_makeitem(collector, name, obj):
if name == "MyClass":
@@ -13,25 +15,29 @@ class TestOEJSKITSpecials(object):
class MyCollector(pytest.Collector):
def reportinfo(self):
return self.fspath, 3, "xyz"
""")
modcol = testdir.getmodulecol("""
"""
)
modcol = testdir.getmodulecol(
"""
import pytest
@pytest.fixture
def arg1(request):
return 42
class MyClass(object):
pass
""")
"""
)
# this hook finds funcarg factories
rep = runner.collect_one_node(collector=modcol)
clscol = rep.result[0]
clscol.obj = lambda arg1: None
clscol.funcargs = {}
pytest._fillfuncargs(clscol)
assert clscol.funcargs['arg1'] == 42
assert clscol.funcargs["arg1"] == 42
def test_autouse_fixture(self, testdir): # rough jstests usage
testdir.makeconftest("""
testdir.makeconftest(
"""
import pytest
def pytest_pycollect_makeitem(collector, name, obj):
if name == "MyClass":
@@ -39,8 +45,10 @@ class TestOEJSKITSpecials(object):
class MyCollector(pytest.Collector):
def reportinfo(self):
return self.fspath, 3, "xyz"
""")
modcol = testdir.getmodulecol("""
"""
)
modcol = testdir.getmodulecol(
"""
import pytest
@pytest.fixture(autouse=True)
def hello():
@@ -50,7 +58,8 @@ class TestOEJSKITSpecials(object):
return 42
class MyClass(object):
pass
""")
"""
)
# this hook finds funcarg factories
rep = runner.collect_one_node(modcol)
clscol = rep.result[0]
@@ -61,6 +70,7 @@ class TestOEJSKITSpecials(object):
def test_wrapped_getfslineno():
def func():
pass
@@ -72,12 +82,14 @@ def test_wrapped_getfslineno():
@wrap
def wrapped_func(x, y, z):
pass
fs, lineno = python.getfslineno(wrapped_func)
fs2, lineno2 = python.getfslineno(wrap)
assert lineno > lineno2, "getfslineno does not unwrap correctly"
class TestMockDecoration(object):
def test_wrapped_getfuncargnames(self):
from _pytest.compat import getfuncargnames
@@ -100,8 +112,10 @@ class TestMockDecoration(object):
from _pytest.compat import getfuncargnames
def wrap(f):
def func():
pass
func.__wrapped__ = f
func.patchings = ["qwe"]
return func
@@ -115,7 +129,8 @@ class TestMockDecoration(object):
def test_unittest_mock(self, testdir):
pytest.importorskip("unittest.mock")
testdir.makepyfile("""
testdir.makepyfile(
"""
import unittest.mock
class T(unittest.TestCase):
@unittest.mock.patch("os.path.abspath")
@@ -123,13 +138,15 @@ class TestMockDecoration(object):
import os
os.path.abspath("hello")
abspath.assert_any_call("hello")
""")
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
def test_unittest_mock_and_fixture(self, testdir):
pytest.importorskip("unittest.mock")
testdir.makepyfile("""
testdir.makepyfile(
"""
import os.path
import unittest.mock
import pytest
@@ -143,14 +160,16 @@ class TestMockDecoration(object):
def test_hello(inject_me):
import os
os.path.abspath("hello")
""")
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
def test_unittest_mock_and_pypi_mock(self, testdir):
pytest.importorskip("unittest.mock")
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile("""
testdir.makepyfile(
"""
import mock
import unittest.mock
class TestBoth(object):
@@ -165,13 +184,15 @@ class TestMockDecoration(object):
import os
os.path.abspath("hello")
abspath.assert_any_call("hello")
""")
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
def test_mock(self, testdir):
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile("""
testdir.makepyfile(
"""
import os
import unittest
import mock
@@ -191,17 +212,20 @@ class TestMockDecoration(object):
os.path.normpath(os.path.abspath("hello"))
normpath.assert_any_call("this")
assert os.path.basename("123") == "mock_basename"
""")
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
calls = reprec.getcalls("pytest_runtest_logreport")
funcnames = [call.report.location[2] for call in calls
if call.report.when == "call"]
funcnames = [
call.report.location[2] for call in calls if call.report.when == "call"
]
assert funcnames == ["T.test_hello", "test_someting"]
def test_mock_sorting(self, testdir):
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile("""
testdir.makepyfile(
"""
import os
import mock
@@ -214,7 +238,8 @@ class TestMockDecoration(object):
@mock.patch("os.path.abspath")
def test_three(abspath):
pass
""")
"""
)
reprec = testdir.inline_run()
calls = reprec.getreports("pytest_runtest_logreport")
calls = [x for x in calls if x.when == "call"]
@@ -223,7 +248,8 @@ class TestMockDecoration(object):
def test_mock_double_patch_issue473(self, testdir):
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile("""
testdir.makepyfile(
"""
from mock import patch
from pytest import mark
@@ -233,20 +259,25 @@ class TestMockDecoration(object):
class TestSimple(object):
def test_simple_thing(self, mock_path, mock_getcwd):
pass
""")
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
class TestReRunTests(object):
def test_rerun(self, testdir):
testdir.makeconftest("""
testdir.makeconftest(
"""
from _pytest.runner import runtestprotocol
def pytest_runtest_protocol(item, nextitem):
runtestprotocol(item, log=False, nextitem=nextitem)
runtestprotocol(item, log=True, nextitem=nextitem)
""")
testdir.makepyfile("""
"""
)
testdir.makepyfile(
"""
import pytest
count = 0
req = None
@@ -259,36 +290,46 @@ class TestReRunTests(object):
count += 1
def test_fix(fix):
pass
""")
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("""
result.stdout.fnmatch_lines(
"""
*fix count 0*
*fix count 1*
""")
result.stdout.fnmatch_lines("""
"""
)
result.stdout.fnmatch_lines(
"""
*2 passed*
""")
"""
)
def test_pytestconfig_is_session_scoped():
from _pytest.fixtures import pytestconfig
assert pytestconfig._pytestfixturefunction.scope == "session"
class TestNoselikeTestAttribute(object):
def test_module_with_global_test(self, testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
__test__ = False
def test_hello():
pass
""")
"""
)
reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
calls = reprec.getreports("pytest_runtest_logreport")
assert not calls
def test_class_and_method(self, testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
__test__ = True
def test_func():
pass
@@ -298,14 +339,16 @@ class TestNoselikeTestAttribute(object):
__test__ = False
def test_method(self):
pass
""")
"""
)
reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
calls = reprec.getreports("pytest_runtest_logreport")
assert not calls
def test_unittest_class(self, testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
import unittest
class TC(unittest.TestCase):
def test_1(self):
@@ -314,7 +357,8 @@ class TestNoselikeTestAttribute(object):
__test__ = False
def test_2(self):
pass
""")
"""
)
reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
call = reprec.getcalls("pytest_collection_modifyitems")[0]
@@ -328,7 +372,8 @@ class TestNoselikeTestAttribute(object):
RPC wrapper), we shouldn't assume this meant "__test__ = True".
"""
# https://github.com/pytest-dev/pytest/issues/1204
testdir.makepyfile("""
testdir.makepyfile(
"""
class MetaModel(type):
def __getattr__(cls, key):
@@ -344,7 +389,8 @@ class TestNoselikeTestAttribute(object):
def test_blah(self):
pass
""")
"""
)
reprec = testdir.inline_run()
assert not reprec.getfailedcollections()
call = reprec.getcalls("pytest_collection_modifyitems")[0]
@@ -355,7 +401,8 @@ class TestNoselikeTestAttribute(object):
class TestParameterize(object):
def test_idfn_marker(self, testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
import pytest
def idfn(param):
@@ -369,15 +416,14 @@ class TestParameterize(object):
@pytest.mark.parametrize('a,b', [(0, 2), (1, 2)], ids=idfn)
def test_params(a, b):
pass
""")
res = testdir.runpytest('--collect-only')
res.stdout.fnmatch_lines([
"*spam-2*",
"*ham-2*",
])
"""
)
res = testdir.runpytest("--collect-only")
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])
def test_idfn_fixture(self, testdir):
testdir.makepyfile("""
testdir.makepyfile(
"""
import pytest
def idfn(param):
@@ -398,9 +444,7 @@ class TestParameterize(object):
def test_params(a, b):
pass
""")
res = testdir.runpytest('--collect-only')
res.stdout.fnmatch_lines([
"*spam-2*",
"*ham-2*",
])
"""
)
res = testdir.runpytest("--collect-only")
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])