From cf7761f91f7b194dd89fae13c356d2d4a4d90d0a Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 6 Aug 2019 12:40:27 -0700 Subject: [PATCH] ran pyupgrade-docs --- doc/en/assert.rst | 4 ++-- doc/en/example/attic.rst | 4 ++-- doc/en/example/markers.rst | 12 ++++++------ doc/en/example/simple.rst | 8 ++++---- doc/en/monkeypatch.rst | 6 +++--- doc/en/skipping.rst | 2 +- doc/en/usage.rst | 2 +- doc/en/writing_plugins.rst | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/doc/en/assert.rst b/doc/en/assert.rst index 465b8d86c..41afc1abf 100644 --- a/doc/en/assert.rst +++ b/doc/en/assert.rst @@ -238,14 +238,14 @@ file which provides an alternative explanation for ``Foo`` objects: def pytest_assertrepr_compare(op, left, right): if isinstance(left, Foo) and isinstance(right, Foo) and op == "==": - return ["Comparing Foo instances:", " vals: %s != %s" % (left.val, right.val)] + return ["Comparing Foo instances:", " vals: {} != {}".format(left.val, right.val)] now, given this test module: .. code-block:: python # content of test_foocompare.py - class Foo(object): + class Foo: def __init__(self, val): self.val = val diff --git a/doc/en/example/attic.rst b/doc/en/example/attic.rst index 9bf3703ce..2ea870062 100644 --- a/doc/en/example/attic.rst +++ b/doc/en/example/attic.rst @@ -18,7 +18,7 @@ example: specifying and selecting acceptance tests return AcceptFixture(request) - class AcceptFixture(object): + class AcceptFixture: def __init__(self, request): if not request.config.getoption("acceptance"): pytest.skip("specify -A to run acceptance tests") @@ -65,7 +65,7 @@ extend the `accept example`_ by putting this in our test module: return arg - class TestSpecialAcceptance(object): + class TestSpecialAcceptance: def test_sometest(self, accept): assert accept.tmpdir.join("special").check() diff --git a/doc/en/example/markers.rst b/doc/en/example/markers.rst index 218ef2707..a1fe65874 100644 --- a/doc/en/example/markers.rst +++ b/doc/en/example/markers.rst @@ -33,7 +33,7 @@ You can "mark" a test function with custom metadata like this: pass - class TestClass(object): + class TestClass: def test_method(self): pass @@ -278,7 +278,7 @@ its test methods: @pytest.mark.webtest - class TestClass(object): + class TestClass: def test_startup(self): pass @@ -295,7 +295,7 @@ Due to legacy reasons, it is possible to set the ``pytestmark`` attribute on a T import pytest - class TestClass(object): + class TestClass: pytestmark = pytest.mark.webtest or if you need to use multiple markers you can use a list: @@ -305,7 +305,7 @@ or if you need to use multiple markers you can use a list: import pytest - class TestClass(object): + class TestClass: pytestmark = [pytest.mark.webtest, pytest.mark.slowtest] You can also set a module level marker:: @@ -523,7 +523,7 @@ code you can read over all such settings. Example: @pytest.mark.glob("class", x=2) - class TestClass(object): + class TestClass: @pytest.mark.glob("function", x=3) def test_something(self): pass @@ -539,7 +539,7 @@ test function. From a conftest file we can read it like this: def pytest_runtest_setup(item): for mark in item.iter_markers(name="glob"): - print("glob args=%s kwargs=%s" % (mark.args, mark.kwargs)) + print("glob args={} kwargs={}".format(mark.args, mark.kwargs)) sys.stdout.flush() Let's run this without capturing output and see what we get: diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 87b68245b..dbfba0fa0 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -238,7 +238,7 @@ Example: def checkconfig(x): __tracebackhide__ = True if not hasattr(x, "config"): - pytest.fail("not configured: %s" % (x,)) + pytest.fail("not configured: {}".format(x)) def test_something(): @@ -280,7 +280,7 @@ this to make sure unexpected exception types aren't hidden: def checkconfig(x): __tracebackhide__ = operator.methodcaller("errisinstance", ConfigException) if not hasattr(x, "config"): - raise ConfigException("not configured: %s" % (x,)) + raise ConfigException("not configured: {}".format(x)) def test_something(): @@ -491,7 +491,7 @@ tests in a class. Here is a test module example: @pytest.mark.incremental - class TestUserHandling(object): + class TestUserHandling: def test_login(self): pass @@ -556,7 +556,7 @@ Here is an example for making a ``db`` fixture available in a directory: import pytest - class DB(object): + class DB: pass diff --git a/doc/en/monkeypatch.rst b/doc/en/monkeypatch.rst index fd277d234..a38f07e79 100644 --- a/doc/en/monkeypatch.rst +++ b/doc/en/monkeypatch.rst @@ -272,7 +272,7 @@ to do this using the ``setenv`` and ``delenv`` method. Our example code to test: username = os.getenv("USER") if username is None: - raise EnvironmentError("USER environment is not set.") + raise OSError("USER environment is not set.") return username.lower() @@ -296,7 +296,7 @@ both paths can be safely tested without impacting the running environment: """Remove the USER env var and assert EnvironmentError is raised.""" monkeypatch.delenv("USER", raising=False) - with pytest.raises(EnvironmentError): + with pytest.raises(OSError): _ = get_os_user_lower() This behavior can be moved into ``fixture`` structures and shared across tests: @@ -323,7 +323,7 @@ This behavior can be moved into ``fixture`` structures and shared across tests: def test_raise_exception(mock_env_missing): - with pytest.raises(EnvironmentError): + with pytest.raises(OSError): _ = get_os_user_lower() diff --git a/doc/en/skipping.rst b/doc/en/skipping.rst index 0f57284b3..d1b308ac0 100644 --- a/doc/en/skipping.rst +++ b/doc/en/skipping.rst @@ -145,7 +145,7 @@ You can use the ``skipif`` marker (as any other marker) on classes: .. code-block:: python @pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") - class TestPosixCalls(object): + class TestPosixCalls: def test_function(self): "will not be setup or run under 'win32' platform" diff --git a/doc/en/usage.rst b/doc/en/usage.rst index 84edb5705..75f5aacfd 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -652,7 +652,7 @@ to all tests. record_testsuite_property("STORAGE_TYPE", "CEPH") - class TestMe(object): + class TestMe: def test_foo(self): assert True diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst index 67a8fcecf..7975f5826 100644 --- a/doc/en/writing_plugins.rst +++ b/doc/en/writing_plugins.rst @@ -693,7 +693,7 @@ declaring the hook functions directly in your plugin module, for example: # contents of myplugin.py - class DeferPlugin(object): + class DeferPlugin: """Simple plugin to defer pytest-xdist hook functions.""" def pytest_testnodedown(self, node, error):