pre-commit run pyupgrade --all-files

This commit is contained in:
Anthony Sottile
2019-06-02 15:32:00 -07:00
committed by Bruno Oliveira
parent 3f1ec520fc
commit a91fe1fedd
100 changed files with 739 additions and 801 deletions

View File

@@ -23,10 +23,10 @@ class MyDocTestRunner(doctest.DocTestRunner):
)
class TestApprox(object):
class TestApprox:
@pytest.fixture
def plus_minus(self):
return u"\u00b1"
return "\u00b1"
def test_repr_string(self, plus_minus):
tol1, tol2, infr = "1.0e-06", "2.0e-06", "inf"
@@ -496,7 +496,7 @@ class TestApprox(object):
assert approx(expected, rel=5e-8, abs=0) != actual
def test_generic_sized_iterable_object(self):
class MySizedIterable(object):
class MySizedIterable:
def __iter__(self):
return iter([1, 2, 3, 4])

View File

@@ -8,7 +8,7 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.nodes import Collector
class TestModule(object):
class TestModule:
def test_failing_import(self, testdir):
modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
pytest.raises(Collector.CollectError, modcol.collect)
@@ -117,7 +117,7 @@ class TestModule(object):
are handled properly (#2336).
"""
testdir.makepyfile(
u"""
"""
# -*- coding: utf-8 -*-
raise ImportError(u'Something bad happened ☺')
"""
@@ -133,7 +133,7 @@ class TestModule(object):
assert result.ret == 2
class TestClass(object):
class TestClass:
def test_class_with_init_warning(self, testdir):
testdir.makepyfile(
"""
@@ -254,7 +254,7 @@ class TestClass(object):
assert result.ret == EXIT_NOTESTSCOLLECTED
class TestFunction(object):
class TestFunction:
def test_getmodulecollector(self, testdir):
item = testdir.getitem("def test_func(): pass")
modcol = item.getparent(pytest.Module)
@@ -513,11 +513,11 @@ class TestFunction(object):
item = testdir.getitem("def test_func(): raise ValueError")
config = item.config
class MyPlugin1(object):
class MyPlugin1:
def pytest_pyfunc_call(self, pyfuncitem):
raise ValueError
class MyPlugin2(object):
class MyPlugin2:
def pytest_pyfunc_call(self, pyfuncitem):
return True
@@ -663,7 +663,7 @@ class TestFunction(object):
assert [x.originalname for x in items] == ["test_func", "test_func"]
class TestSorting(object):
class TestSorting:
def test_check_equality(self, testdir):
modcol = testdir.getmodulecol(
"""
@@ -715,7 +715,7 @@ class TestSorting(object):
assert [item.name for item in colitems] == ["test_b", "test_a"]
class TestConftestCustomization(object):
class TestConftestCustomization:
def test_pytest_pycollect_module(self, testdir):
testdir.makeconftest(
"""
@@ -890,7 +890,7 @@ def test_modulecol_roundtrip(testdir):
assert modcol.name == newcol.name
class TestTracebackCutting(object):
class TestTracebackCutting:
def test_skip_simple(self):
with pytest.raises(pytest.skip.Exception) as excinfo:
pytest.skip("xxx")
@@ -1019,7 +1019,7 @@ class TestTracebackCutting(object):
assert filter_traceback(tb[-1])
class TestReportInfo(object):
class TestReportInfo:
def test_itemreport_reportinfo(self, testdir, linecomp):
testdir.makeconftest(
"""
@@ -1257,7 +1257,7 @@ def test_syntax_error_with_non_ascii_chars(testdir):
"""Fix decoding issue while formatting SyntaxErrors during collection (#578)
"""
testdir.makepyfile(
u"""
"""
# -*- coding: utf-8 -*-

View File

@@ -31,7 +31,7 @@ def test_getfuncargnames():
assert fixtures.getfuncargnames(h) == ("arg1", "arg2")
class A(object):
class A:
def f(self, arg1, arg2="hello"):
pass
@@ -44,7 +44,7 @@ def test_getfuncargnames():
@pytest.mark.pytester_example_path("fixtures/fill_fixtures")
class TestFillFixtures(object):
class TestFillFixtures:
def test_fillfuncargs_exposed(self):
# used by oejskit, kept for compatibility
assert pytest._fillfuncargs == fixtures.fillfixtures
@@ -442,7 +442,7 @@ class TestFillFixtures(object):
assert result.ret == 0
class TestRequestBasic(object):
class TestRequestBasic:
def test_request_attributes(self, testdir):
item = testdir.getitem(
"""
@@ -901,7 +901,7 @@ class TestRequestBasic(object):
reprec.assertoutcome(passed=2)
class TestRequestMarking(object):
class TestRequestMarking:
def test_applymarker(self, testdir):
item1, item2 = testdir.getitems(
"""
@@ -971,7 +971,7 @@ class TestRequestMarking(object):
reprec.assertoutcome(passed=2)
class TestFixtureUsages(object):
class TestFixtureUsages:
def test_noargfixturedec(self, testdir):
testdir.makepyfile(
"""
@@ -1302,7 +1302,7 @@ class TestFixtureUsages(object):
result.stdout.fnmatch_lines(["* 2 passed in *"])
class TestFixtureManagerParseFactories(object):
class TestFixtureManagerParseFactories:
@pytest.fixture
def testdir(self, request):
testdir = request.getfixturevalue("testdir")
@@ -1528,7 +1528,7 @@ class TestFixtureManagerParseFactories(object):
result.stdout.fnmatch_lines(["*passed*"])
class TestAutouseDiscovery(object):
class TestAutouseDiscovery:
@pytest.fixture
def testdir(self, testdir):
testdir.makeconftest(
@@ -1704,7 +1704,7 @@ class TestAutouseDiscovery(object):
reprec.assertoutcome(passed=3)
class TestAutouseManagement(object):
class TestAutouseManagement:
def test_autouse_conftest_mid_directory(self, testdir):
pkgdir = testdir.mkpydir("xyz123")
pkgdir.join("conftest.py").write(
@@ -1952,7 +1952,7 @@ class TestAutouseManagement(object):
reprec.assertoutcome(passed=2)
class TestFixtureMarker(object):
class TestFixtureMarker:
def test_parametrize(self, testdir):
testdir.makepyfile(
"""
@@ -2908,7 +2908,7 @@ class TestFixtureMarker(object):
assert out1 == out2
class TestRequestScopeAccess(object):
class TestRequestScopeAccess:
pytestmark = pytest.mark.parametrize(
("scope", "ok", "error"),
[
@@ -2962,7 +2962,7 @@ class TestRequestScopeAccess(object):
reprec.assertoutcome(passed=1)
class TestErrors(object):
class TestErrors:
def test_subfactory_missing_funcarg(self, testdir):
testdir.makepyfile(
"""
@@ -3029,7 +3029,7 @@ class TestErrors(object):
)
class TestShowFixtures(object):
class TestShowFixtures:
def test_funcarg_compat(self, testdir):
config = testdir.parseconfigure("--funcargs")
assert config.option.showfixtures
@@ -3317,7 +3317,7 @@ class TestShowFixtures(object):
pass
class TestContextManagerFixtureFuncs(object):
class TestContextManagerFixtureFuncs:
@pytest.fixture(params=["fixture", "yield_fixture"])
def flavor(self, request, testdir, monkeypatch):
monkeypatch.setenv("PYTEST_FIXTURE_FLAVOR", request.param)
@@ -3465,7 +3465,7 @@ class TestContextManagerFixtureFuncs(object):
result.stdout.fnmatch_lines(["*mew*"])
class TestParameterizedSubRequest(object):
class TestParameterizedSubRequest:
def test_call_from_fixture(self, testdir):
testdir.makepyfile(
test_call_from_fixture="""
@@ -3644,7 +3644,7 @@ def test_pytest_fixture_setup_and_post_finalizer_hook(testdir):
)
class TestScopeOrdering(object):
class TestScopeOrdering:
"""Class of tests that ensure fixtures are ordered based on their scopes (#2405)"""
@pytest.mark.parametrize("variant", ["mark", "autouse"])

View File

@@ -3,7 +3,7 @@ from _pytest import python
from _pytest import runner
class TestOEJSKITSpecials(object):
class TestOEJSKITSpecials:
def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage
testdir.makeconftest(
"""
@@ -86,7 +86,7 @@ def test_wrapped_getfslineno():
assert lineno > lineno2, "getfslineno does not unwrap correctly"
class TestMockDecoration(object):
class TestMockDecoration:
def test_wrapped_getfuncargnames(self):
from _pytest.compat import getfuncargnames
@@ -263,7 +263,7 @@ class TestMockDecoration(object):
reprec.assertoutcome(passed=1)
class TestReRunTests(object):
class TestReRunTests:
def test_rerun(self, testdir):
testdir.makeconftest(
"""
@@ -309,7 +309,7 @@ def test_pytestconfig_is_session_scoped():
assert pytestconfig._pytestfixturefunction.scope == "session"
class TestNoselikeTestAttribute(object):
class TestNoselikeTestAttribute:
def test_module_with_global_test(self, testdir):
testdir.makepyfile(
"""
@@ -393,7 +393,7 @@ class TestNoselikeTestAttribute(object):
assert not call.items
class TestParameterize(object):
class TestParameterize:
"""#351"""
def test_idfn_marker(self, testdir):

View File

@@ -4,7 +4,6 @@ import textwrap
import attr
import hypothesis
import six
from hypothesis import strategies
import pytest
@@ -13,19 +12,19 @@ from _pytest import python
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
class TestMetafunc(object):
class TestMetafunc:
def Metafunc(self, func, config=None):
# the unit tests of this class check if things work correctly
# on the funcarg level, so we don't need a full blown
# initiliazation
class FixtureInfo(object):
class FixtureInfo:
name2fixturedefs = None
def __init__(self, names):
self.names_closure = names
@attr.s
class DefinitionMock(object):
class DefinitionMock:
obj = attr.ib()
names = fixtures.getfuncargnames(func)
@@ -79,7 +78,7 @@ class TestMetafunc(object):
from _pytest.python import _find_parametrized_scope
@attr.s
class DummyFixtureDef(object):
class DummyFixtureDef:
scope = attr.ib()
fixtures_defs = dict(
@@ -138,9 +137,9 @@ class TestMetafunc(object):
pass
metafunc = self.Metafunc(func)
metafunc.parametrize("x", [1, 2], ids=[u"basic", u"advanced"])
metafunc.parametrize("x", [1, 2], ids=["basic", "advanced"])
ids = [x.id for x in metafunc._calls]
assert ids == [u"basic", u"advanced"]
assert ids == ["basic", "advanced"]
def test_parametrize_with_wrong_number_of_ids(self, testdir):
def func(x, y):
@@ -162,7 +161,7 @@ class TestMetafunc(object):
def func(y):
pass
class MockConfig(object):
class MockConfig:
def getini(self, name):
return ""
@@ -183,7 +182,7 @@ class TestMetafunc(object):
metafunc = self.Metafunc(func)
class A(object):
class A:
pass
metafunc.parametrize("x", [A(), A()])
@@ -201,7 +200,7 @@ class TestMetafunc(object):
from _pytest.python import _idval
escaped = _idval(value, "a", 6, None, item=None, config=None)
assert isinstance(escaped, six.text_type)
assert isinstance(escaped, str)
escaped.encode("ascii")
def test_unicode_idval(self):
@@ -213,12 +212,12 @@ class TestMetafunc(object):
from _pytest.python import _idval
values = [
(u"", ""),
(u"ascii", "ascii"),
(u"ação", "a\\xe7\\xe3o"),
(u"josé@blah.com", "jos\\xe9@blah.com"),
("", ""),
("ascii", "ascii"),
("ação", "a\\xe7\\xe3o"),
("josé@blah.com", "jos\\xe9@blah.com"),
(
u"δοκ.ιμή@παράδειγμα.δοκιμή",
"δοκ.ιμή@παράδειγμα.δοκιμή",
"\\u03b4\\u03bf\\u03ba.\\u03b9\\u03bc\\u03ae@\\u03c0\\u03b1\\u03c1\\u03ac\\u03b4\\u03b5\\u03b9\\u03b3"
"\\u03bc\\u03b1.\\u03b4\\u03bf\\u03ba\\u03b9\\u03bc\\u03ae",
),
@@ -233,7 +232,7 @@ class TestMetafunc(object):
"""
from _pytest.python import _idval
class MockConfig(object):
class MockConfig:
def __init__(self, config):
self.config = config
@@ -250,8 +249,8 @@ class TestMetafunc(object):
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values = [
(u"ação", MockConfig({option: True}), u"ação"),
(u"ação", MockConfig({option: False}), "a\\xe7\\xe3o"),
("ação", MockConfig({option: True}), "ação"),
("ação", MockConfig({option: False}), "a\\xe7\\xe3o"),
]
for val, config, expected in values:
assert _idval(val, "a", 6, None, item=None, config=config) == expected
@@ -269,7 +268,7 @@ class TestMetafunc(object):
(b"", ""),
(b"\xc3\xb4\xff\xe4", "\\xc3\\xb4\\xff\\xe4"),
(b"ascii", "ascii"),
(u"αρά".encode("utf-8"), "\\xce\\xb1\\xcf\\x81\\xce\\xac"),
("αρά".encode(), "\\xce\\xb1\\xcf\\x81\\xce\\xac"),
]
for val, expected in values:
assert _idval(val, "a", 6, idfn=None, item=None, config=None) == expected
@@ -280,7 +279,7 @@ class TestMetafunc(object):
"""
from _pytest.python import _idval
class TestClass(object):
class TestClass:
pass
def test_function():
@@ -304,7 +303,7 @@ class TestMetafunc(object):
)
assert result == ["a0-1.0", "a1-b1"]
# unicode mixing, issue250
result = idmaker((u"a", "b"), [pytest.param({}, b"\xc3\xb4")])
result = idmaker(("a", "b"), [pytest.param({}, b"\xc3\xb4")])
assert result == ["a0-\\xc3\\xb4"]
def test_idmaker_with_bytes_regex(self):
@@ -330,7 +329,7 @@ class TestMetafunc(object):
pytest.param({7}, set("seven")),
pytest.param(tuple("eight"), (8, -8, 8)),
pytest.param(b"\xc3\xb4", b"name"),
pytest.param(b"\xc3\xb4", u"other"),
pytest.param(b"\xc3\xb4", "other"),
],
)
assert result == [
@@ -428,7 +427,7 @@ class TestMetafunc(object):
"""
from _pytest.python import idmaker
class MockConfig(object):
class MockConfig:
def __init__(self, config):
self.config = config
@@ -445,12 +444,12 @@ class TestMetafunc(object):
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values = [
(MockConfig({option: True}), u"ação"),
(MockConfig({option: True}), "ação"),
(MockConfig({option: False}), "a\\xe7\\xe3o"),
]
for config, expected in values:
result = idmaker(
("a",), [pytest.param("string")], idfn=lambda _: u"ação", config=config
("a",), [pytest.param("string")], idfn=lambda _: "ação", config=config
)
assert result == [expected]
@@ -461,7 +460,7 @@ class TestMetafunc(object):
"""
from _pytest.python import idmaker
class MockConfig(object):
class MockConfig:
def __init__(self, config):
self.config = config
@@ -478,12 +477,12 @@ class TestMetafunc(object):
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values = [
(MockConfig({option: True}), u"ação"),
(MockConfig({option: True}), "ação"),
(MockConfig({option: False}), "a\\xe7\\xe3o"),
]
for config, expected in values:
result = idmaker(
("a",), [pytest.param("string")], ids=[u"ação"], config=config
("a",), [pytest.param("string")], ids=["ação"], config=config
)
assert result == [expected]
@@ -888,7 +887,7 @@ class TestMetafunc(object):
assert fixtures._format_args(function4) == "(arg1, *args, **kwargs)"
class TestMetafuncFunctional(object):
class TestMetafuncFunctional:
def test_attributes(self, testdir):
p = testdir.makepyfile(
"""
@@ -1324,7 +1323,7 @@ class TestMetafuncFunctional(object):
)
class TestMetafuncFunctionalAuto(object):
class TestMetafuncFunctionalAuto:
"""
Tests related to automatically find out the correct scope for parametrized tests (#1832).
"""
@@ -1486,7 +1485,7 @@ class TestMetafuncFunctionalAuto(object):
assert output.count("preparing foo-3") == 1
class TestMarkersWithParametrization(object):
class TestMarkersWithParametrization:
"""#308"""
def test_simple_mark(self, testdir):

View File

@@ -5,7 +5,7 @@ from _pytest.outcomes import Failed
from _pytest.warning_types import PytestDeprecationWarning
class TestRaises(object):
class TestRaises:
def test_raises(self):
source = "int('qwe')"
with pytest.warns(PytestDeprecationWarning):
@@ -33,7 +33,7 @@ class TestRaises(object):
pytest.raises(ValueError, int, "hello")
def test_raises_callable_no_exception(self):
class A(object):
class A:
def __call__(self):
pass
@@ -187,7 +187,7 @@ class TestRaises(object):
"""
import gc
class T(object):
class T:
def __call__(self):
raise ValueError
@@ -235,8 +235,6 @@ class TestRaises(object):
int("asdf")
def test_raises_exception_looks_iterable(self):
from six import add_metaclass
class Meta(type(object)):
def __getitem__(self, item):
return 1 / 0
@@ -244,8 +242,7 @@ class TestRaises(object):
def __len__(self):
return 1
@add_metaclass(Meta)
class ClassLooksIterableException(Exception):
class ClassLooksIterableException(Exception, metaclass=Meta):
pass
with pytest.raises(

View File

@@ -1,5 +1,3 @@
def test_no_items_should_not_show_output(testdir):
result = testdir.runpytest("--fixtures-per-test")
assert "fixtures used by" not in result.stdout.str()