ran pyupgrade-docs again
This commit is contained in:
parent
7f90e74e02
commit
75d0b899bb
|
@ -190,13 +190,13 @@ only have to work a bit to construct the correct arguments for pytest's
|
||||||
idlist.append(scenario[0])
|
idlist.append(scenario[0])
|
||||||
items = scenario[1].items()
|
items = scenario[1].items()
|
||||||
argnames = [x[0] for x in items]
|
argnames = [x[0] for x in items]
|
||||||
argvalues.append(([x[1] for x in items]))
|
argvalues.append([x[1] for x in items])
|
||||||
metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")
|
metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")
|
||||||
|
|
||||||
scenario1 = ('basic', {'attribute': 'value'})
|
scenario1 = ('basic', {'attribute': 'value'})
|
||||||
scenario2 = ('advanced', {'attribute': 'value2'})
|
scenario2 = ('advanced', {'attribute': 'value2'})
|
||||||
|
|
||||||
class TestSampleWithScenarios(object):
|
class TestSampleWithScenarios:
|
||||||
scenarios = [scenario1, scenario2]
|
scenarios = [scenario1, scenario2]
|
||||||
|
|
||||||
def test_demo1(self, attribute):
|
def test_demo1(self, attribute):
|
||||||
|
@ -277,9 +277,9 @@ creates a database object for the actual test invocations::
|
||||||
if 'db' in metafunc.fixturenames:
|
if 'db' in metafunc.fixturenames:
|
||||||
metafunc.parametrize("db", ['d1', 'd2'], indirect=True)
|
metafunc.parametrize("db", ['d1', 'd2'], indirect=True)
|
||||||
|
|
||||||
class DB1(object):
|
class DB1:
|
||||||
"one database object"
|
"one database object"
|
||||||
class DB2(object):
|
class DB2:
|
||||||
"alternative database object"
|
"alternative database object"
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -398,7 +398,7 @@ parametrizer`_ but in a lot less code::
|
||||||
metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
|
metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
|
||||||
for funcargs in funcarglist])
|
for funcargs in funcarglist])
|
||||||
|
|
||||||
class TestClass(object):
|
class TestClass:
|
||||||
# a map specifying multiple argument sets for a test method
|
# a map specifying multiple argument sets for a test method
|
||||||
params = {
|
params = {
|
||||||
'test_equals': [dict(a=1, b=2), dict(a=3, b=3), ],
|
'test_equals': [dict(a=1, b=2), dict(a=3, b=3), ],
|
||||||
|
|
|
@ -136,7 +136,7 @@ that match ``*_check``. For example, if we have::
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# content of check_myapp.py
|
# content of check_myapp.py
|
||||||
class CheckMyApp(object):
|
class CheckMyApp:
|
||||||
def simple_check(self):
|
def simple_check(self):
|
||||||
pass
|
pass
|
||||||
def complex_check(self):
|
def complex_check(self):
|
||||||
|
|
|
@ -16,7 +16,7 @@ calls it::
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def callattr_ahead_of_alltests(request):
|
def callattr_ahead_of_alltests(request):
|
||||||
print("callattr_ahead_of_alltests called")
|
print("callattr_ahead_of_alltests called")
|
||||||
seen = set([None])
|
seen = {None}
|
||||||
session = request.node
|
session = request.node
|
||||||
for item in session.items:
|
for item in session.items:
|
||||||
cls = item.getparent(pytest.Class)
|
cls = item.getparent(pytest.Class)
|
||||||
|
@ -32,7 +32,7 @@ will be called ahead of running any tests::
|
||||||
|
|
||||||
# content of test_module.py
|
# content of test_module.py
|
||||||
|
|
||||||
class TestHello(object):
|
class TestHello:
|
||||||
@classmethod
|
@classmethod
|
||||||
def callme(cls):
|
def callme(cls):
|
||||||
print("callme called!")
|
print("callme called!")
|
||||||
|
@ -43,7 +43,7 @@ will be called ahead of running any tests::
|
||||||
def test_method2(self):
|
def test_method2(self):
|
||||||
print("test_method1 called")
|
print("test_method1 called")
|
||||||
|
|
||||||
class TestOther(object):
|
class TestOther:
|
||||||
@classmethod
|
@classmethod
|
||||||
def callme(cls):
|
def callme(cls):
|
||||||
print("callme other called")
|
print("callme other called")
|
||||||
|
|
|
@ -496,7 +496,7 @@ read an optional server URL from the test module which uses our fixture::
|
||||||
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
|
server = getattr(request.module, "smtpserver", "smtp.gmail.com")
|
||||||
smtp_connection = smtplib.SMTP(server, 587, timeout=5)
|
smtp_connection = smtplib.SMTP(server, 587, timeout=5)
|
||||||
yield smtp_connection
|
yield smtp_connection
|
||||||
print("finalizing %s (%s)" % (smtp_connection, server))
|
print("finalizing {} ({})".format(smtp_connection, server))
|
||||||
smtp_connection.close()
|
smtp_connection.close()
|
||||||
|
|
||||||
We use the ``request.module`` attribute to optionally obtain an
|
We use the ``request.module`` attribute to optionally obtain an
|
||||||
|
@ -820,7 +820,7 @@ and instantiate an object ``app`` where we stick the already defined
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
class App(object):
|
class App:
|
||||||
def __init__(self, smtp_connection):
|
def __init__(self, smtp_connection):
|
||||||
self.smtp_connection = smtp_connection
|
self.smtp_connection = smtp_connection
|
||||||
|
|
||||||
|
@ -902,7 +902,7 @@ to show the setup/teardown flow::
|
||||||
def test_1(modarg):
|
def test_1(modarg):
|
||||||
print(" RUN test1 with modarg %s" % modarg)
|
print(" RUN test1 with modarg %s" % modarg)
|
||||||
def test_2(otherarg, modarg):
|
def test_2(otherarg, modarg):
|
||||||
print(" RUN test2 with otherarg %s and modarg %s" % (otherarg, modarg))
|
print(" RUN test2 with otherarg {} and modarg {}".format(otherarg, modarg))
|
||||||
|
|
||||||
|
|
||||||
Let's run the tests in verbose mode and with looking at the print-output:
|
Let's run the tests in verbose mode and with looking at the print-output:
|
||||||
|
@ -1001,7 +1001,7 @@ and declare its use in a test module via a ``usefixtures`` marker::
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.mark.usefixtures("cleandir")
|
@pytest.mark.usefixtures("cleandir")
|
||||||
class TestDirectoryInit(object):
|
class TestDirectoryInit:
|
||||||
def test_cwd_starts_empty(self):
|
def test_cwd_starts_empty(self):
|
||||||
assert os.listdir(os.getcwd()) == []
|
assert os.listdir(os.getcwd()) == []
|
||||||
with open("myfile", "w") as f:
|
with open("myfile", "w") as f:
|
||||||
|
@ -1086,7 +1086,7 @@ self-contained implementation of this idea::
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
class DB(object):
|
class DB:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.intransaction = []
|
self.intransaction = []
|
||||||
def begin(self, name):
|
def begin(self, name):
|
||||||
|
@ -1098,7 +1098,7 @@ self-contained implementation of this idea::
|
||||||
def db():
|
def db():
|
||||||
return DB()
|
return DB()
|
||||||
|
|
||||||
class TestClass(object):
|
class TestClass:
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def transact(self, request, db):
|
def transact(self, request, db):
|
||||||
db.begin(request.function.__name__)
|
db.begin(request.function.__name__)
|
||||||
|
@ -1162,7 +1162,7 @@ and then e.g. have a TestClass using it by declaring the need::
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@pytest.mark.usefixtures("transact")
|
@pytest.mark.usefixtures("transact")
|
||||||
class TestClass(object):
|
class TestClass:
|
||||||
def test_method1(self):
|
def test_method1(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ a per-session Database object::
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# content of conftest.py
|
# content of conftest.py
|
||||||
class Database(object):
|
class Database:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print("database instance created")
|
print("database instance created")
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
|
|
|
@ -114,7 +114,7 @@ Once you develop multiple tests, you may want to group them into a class. pytest
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# content of test_class.py
|
# content of test_class.py
|
||||||
class TestClass(object):
|
class TestClass:
|
||||||
def test_one(self):
|
def test_one(self):
|
||||||
x = "this"
|
x = "this"
|
||||||
assert 'h' in x
|
assert 'h' in x
|
||||||
|
|
|
@ -93,7 +93,7 @@ it from a unittest-style test::
|
||||||
|
|
||||||
@pytest.fixture(scope="class")
|
@pytest.fixture(scope="class")
|
||||||
def db_class(request):
|
def db_class(request):
|
||||||
class DummyDB(object):
|
class DummyDB:
|
||||||
pass
|
pass
|
||||||
# set a class attribute on the invoking test context
|
# set a class attribute on the invoking test context
|
||||||
request.cls.db = DummyDB()
|
request.cls.db = DummyDB()
|
||||||
|
|
|
@ -774,7 +774,7 @@ You can specify additional plugins to ``pytest.main``::
|
||||||
|
|
||||||
# content of myinvoke.py
|
# content of myinvoke.py
|
||||||
import pytest
|
import pytest
|
||||||
class MyPlugin(object):
|
class MyPlugin:
|
||||||
def pytest_sessionfinish(self):
|
def pytest_sessionfinish(self):
|
||||||
print("*** test run reporting finishing")
|
print("*** test run reporting finishing")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue