ran pyupgrade-docs

This commit is contained in:
boris 2019-08-06 12:40:27 -07:00
parent 68c486a25f
commit cf7761f91f
8 changed files with 20 additions and 20 deletions

View File

@ -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

View File

@ -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()

View File

@ -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:

View File

@ -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

View File

@ -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()

View File

@ -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"

View File

@ -652,7 +652,7 @@ to all tests.
record_testsuite_property("STORAGE_TYPE", "CEPH")
class TestMe(object):
class TestMe:
def test_foo(self):
assert True

View File

@ -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):