Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyupgrade docs to Python 3 #5705

Merged
merged 7 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/en/assert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,17 @@ 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

Expand Down
5 changes: 4 additions & 1 deletion doc/en/builtin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a

no tests ran in 0.12 seconds

You can also interactively ask for help, e.g. by typing on the Python interactive prompt something like::
You can also interactively ask for help, e.g. by typing on the Python interactive prompt something like:

.. code-block:: python

import pytest

help(pytest)
14 changes: 11 additions & 3 deletions doc/en/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ Other plugins may access the `config.cache`_ object to set/get
Rerunning only failures or failures first
-----------------------------------------------

First, let's create 50 test invocation of which only 2 fail::
First, let's create 50 test invocation of which only 2 fail:

.. code-block:: python

# content of test_50.py
import pytest


@pytest.mark.parametrize("i", range(50))
def test_num(i):
if i in (17, 25):
pytest.fail("bad luck")
pytest.fail("bad luck")

If you run this for the first time you will see two failures:

Expand Down Expand Up @@ -183,15 +186,19 @@ The new config.cache object
Plugins or conftest.py support code can get a cached value using the
pytest ``config`` object. Here is a basic example plugin which
implements a :ref:`fixture` which re-uses previously created state
across pytest invocations::
across pytest invocations:

.. code-block:: python

# content of test_caching.py
import pytest
import time


def expensive_computation():
print("running expensive computation...")


@pytest.fixture
def mydata(request):
val = request.config.cache.get("example/value", None)
Expand All @@ -201,6 +208,7 @@ across pytest invocations::
request.config.cache.set("example/value", val)
return val


def test_function(mydata):
assert mydata == 23

Expand Down
7 changes: 6 additions & 1 deletion doc/en/capture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ Using print statements for debugging
---------------------------------------------------

One primary benefit of the default capturing of stdout/stderr output
is that you can use print statements for debugging::
is that you can use print statements for debugging:

.. code-block:: python

# content of test_module.py


def setup_function(function):
print("setting up %s" % function)


def test_func1():
assert True


def test_func2():
assert False

Expand Down
4 changes: 3 additions & 1 deletion doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ Internal classes accessed through ``Node``
.. versionremoved:: 4.0

Access of ``Module``, ``Function``, ``Class``, ``Instance``, ``File`` and ``Item`` through ``Node`` instances now issue
this warning::
this warning:

.. code-block:: text

usage of Function.Module is deprecated, please use pytest.Module instead

Expand Down
16 changes: 12 additions & 4 deletions doc/en/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,21 @@ namespace in which your doctests run. It is intended to be used within
your own fixtures to provide the tests that use them with context.

``doctest_namespace`` is a standard ``dict`` object into which you
place the objects you want to appear in the doctest namespace::
place the objects you want to appear in the doctest namespace:

.. code-block:: python

# content of conftest.py
import numpy


@pytest.fixture(autouse=True)
def add_np(doctest_namespace):
doctest_namespace['np'] = numpy
doctest_namespace["np"] = numpy

which can then be used in your doctests directly::
which can then be used in your doctests directly:

.. code-block:: python

# content of numpy.py
def arange():
Expand All @@ -219,7 +225,9 @@ Skipping tests dynamically

.. versionadded:: 4.4

You can use ``pytest.skip`` to dynamically skip doctests. For example::
You can use ``pytest.skip`` to dynamically skip doctests. For example:

.. code-block:: text

>>> import sys, pytest
>>> if sys.platform.startswith('win'):
Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/attic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
12 changes: 6 additions & 6 deletions doc/en/example/markers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -278,7 +278,7 @@ its test methods:


@pytest.mark.webtest
class TestClass(object):
class TestClass:
def test_startup(self):
pass

Expand All @@ -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:
Expand All @@ -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::
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading