Merge pull request #2260 from MichalTHEDUDE/feature/NewStyleClasses-2147

New-style classes implemented for python 2.7 - #2147
This commit is contained in:
Bruno Oliveira 2017-02-16 19:05:09 -02:00 committed by GitHub
commit abd6ad3751
61 changed files with 351 additions and 349 deletions

View File

@ -108,6 +108,7 @@ Michael Aquilina
Michael Birtwell Michael Birtwell
Michael Droettboom Michael Droettboom
Michael Seifert Michael Seifert
Michal Wajszczuk
Mike Lundy Mike Lundy
Ned Batchelder Ned Batchelder
Neven Mundar Neven Mundar

View File

@ -21,7 +21,7 @@ Changes
------- -------
* Old-style classes have been changed to new-style classes in order to improve * Old-style classes have been changed to new-style classes in order to improve
compatability with Python 2. Thanks to `@mandeep`_ for the PR (`#2147`_). compatibility with Python 2. Thanks to `@MichalTHEDUDE`_ and `@mandeep`_ for the PR (`#2147`_).
* It is now possible to skip test classes from being collected by setting a * It is now possible to skip test classes from being collected by setting a
``__test__`` attribute to ``False`` in the class body (`#2007`_). Thanks ``__test__`` attribute to ``False`` in the class body (`#2007`_). Thanks
@ -61,6 +61,7 @@ Changes
.. _@wheerd: https://github.com/wheerd .. _@wheerd: https://github.com/wheerd
.. _@fogo: https://github.com/fogo .. _@fogo: https://github.com/fogo
.. _@mandeep: https://github.com/mandeep .. _@mandeep: https://github.com/mandeep
.. _@MichalTHEDUDE: https://github.com/MichalTHEDUDE
.. _@unsignedint: https://github.com/unsignedint .. _@unsignedint: https://github.com/unsignedint
.. _@Kriechi: https://github.com/Kriechi .. _@Kriechi: https://github.com/Kriechi

View File

@ -167,7 +167,7 @@ def normalize_hookimpl_opts(opts):
opts.setdefault("optionalhook", False) opts.setdefault("optionalhook", False)
class _TagTracer: class _TagTracer(object):
def __init__(self): def __init__(self):
self._tag2proc = {} self._tag2proc = {}
self.writer = None self.writer = None
@ -214,7 +214,7 @@ class _TagTracer:
self._tag2proc[tags] = processor self._tag2proc[tags] = processor
class _TagTracerSub: class _TagTracerSub(object):
def __init__(self, root, tags): def __init__(self, root, tags):
self.root = root self.root = root
self.tags = tags self.tags = tags
@ -254,7 +254,7 @@ def _wrapped_call(wrap_controller, func):
return call_outcome.get_result() return call_outcome.get_result()
class _CallOutcome: class _CallOutcome(object):
""" Outcome of a function call, either an exception or a proper result. """ Outcome of a function call, either an exception or a proper result.
Calling the ``get_result`` method will return the result or reraise Calling the ``get_result`` method will return the result or reraise
the exception raised when the function was called. """ the exception raised when the function was called. """
@ -286,7 +286,7 @@ def _reraise(cls, val, tb):
""") """)
class _TracedHookExecution: class _TracedHookExecution(object):
def __init__(self, pluginmanager, before, after): def __init__(self, pluginmanager, before, after):
self.pluginmanager = pluginmanager self.pluginmanager = pluginmanager
self.before = before self.before = before
@ -580,7 +580,7 @@ class PluginManager(object):
return orig return orig
class _MultiCall: class _MultiCall(object):
""" execute a call into multiple python functions/methods. """ """ execute a call into multiple python functions/methods. """
# XXX note that the __multicall__ argument is supported only # XXX note that the __multicall__ argument is supported only
@ -673,7 +673,7 @@ def varnames(func, startindex=None):
return x return x
class _HookRelay: class _HookRelay(object):
""" hook holder object for performing 1:N hook calls where N is the number """ hook holder object for performing 1:N hook calls where N is the number
of registered plugins. of registered plugins.

View File

@ -223,7 +223,7 @@ provides an alternative explanation for ``Foo`` objects::
now, given this test module:: now, given this test module::
# content of test_foocompare.py # content of test_foocompare.py
class Foo: class Foo(object):
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val

View File

@ -128,7 +128,7 @@ def test_attribute_multiple():
def globf(x): def globf(x):
return x+1 return x+1
class TestRaises: class TestRaises(object):
def test_raises(self): def test_raises(self):
s = 'qwe' s = 'qwe'
raises(TypeError, "int(s)") raises(TypeError, "int(s)")
@ -167,7 +167,7 @@ def test_dynamic_compile_shows_nicely():
class TestMoreErrors: class TestMoreErrors(object):
def test_complex_error(self): def test_complex_error(self):
def f(): def f():
return 44 return 44
@ -213,23 +213,23 @@ class TestMoreErrors:
x = 0 x = 0
class TestCustomAssertMsg: class TestCustomAssertMsg(object):
def test_single_line(self): def test_single_line(self):
class A: class A(object):
a = 1 a = 1
b = 2 b = 2
assert A.a == b, "A.a appears not to be b" assert A.a == b, "A.a appears not to be b"
def test_multiline(self): def test_multiline(self):
class A: class A(object):
a = 1 a = 1
b = 2 b = 2
assert A.a == b, "A.a appears not to be b\n" \ assert A.a == b, "A.a appears not to be b\n" \
"or does not appear to be b\none of those" "or does not appear to be b\none of those"
def test_custom_repr(self): def test_custom_repr(self):
class JSON: class JSON(object):
a = 1 a = 1
def __repr__(self): def __repr__(self):
return "This is JSON\n{\n 'foo': 'bar'\n}" return "This is JSON\n{\n 'foo': 'bar'\n}"

View File

@ -1,7 +1,7 @@
def setup_module(module): def setup_module(module):
module.TestStateFullThing.classcount = 0 module.TestStateFullThing.classcount = 0
class TestStateFullThing: class TestStateFullThing(object):
def setup_class(cls): def setup_class(cls):
cls.classcount += 1 cls.classcount += 1

View File

@ -15,7 +15,7 @@ example: specifying and selecting acceptance tests
def pytest_funcarg__accept(request): def pytest_funcarg__accept(request):
return AcceptFixture(request) return AcceptFixture(request)
class AcceptFixture: class AcceptFixture(object):
def __init__(self, request): def __init__(self, request):
if not request.config.option.acceptance: if not request.config.option.acceptance:
pytest.skip("specify -A to run acceptance tests") pytest.skip("specify -A to run acceptance tests")
@ -61,7 +61,7 @@ extend the `accept example`_ by putting this in our test module:
arg.tmpdir.mkdir("special") arg.tmpdir.mkdir("special")
return arg return arg
class TestSpecialAcceptance: class TestSpecialAcceptance(object):
def test_sometest(self, accept): def test_sometest(self, accept):
assert accept.tmpdir.join("special").check() assert accept.tmpdir.join("special").check()

View File

@ -7,7 +7,7 @@ def setup(request):
yield setup yield setup
setup.finalize() setup.finalize()
class CostlySetup: class CostlySetup(object):
def __init__(self): def __init__(self):
import time import time
print ("performing costly setup") print ("performing costly setup")

View File

@ -21,7 +21,7 @@ You can "mark" a test function with custom metadata like this::
pass pass
def test_another(): def test_another():
pass pass
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
@ -242,7 +242,7 @@ its test methods::
# content of test_mark_classlevel.py # content of test_mark_classlevel.py
import pytest import pytest
@pytest.mark.webtest @pytest.mark.webtest
class TestClass: class TestClass(object):
def test_startup(self): def test_startup(self):
pass pass
def test_startup_and_more(self): def test_startup_and_more(self):
@ -256,14 +256,14 @@ To remain backward-compatible with Python 2.4 you can also set a
import pytest import pytest
class TestClass: class TestClass(object):
pytestmark = pytest.mark.webtest pytestmark = pytest.mark.webtest
or if you need to use multiple markers you can use a list:: or if you need to use multiple markers you can use a list::
import pytest import pytest
class TestClass: class TestClass(object):
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest] pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
You can also set a module level marker:: You can also set a module level marker::
@ -407,7 +407,7 @@ code you can read over all such settings. Example::
pytestmark = pytest.mark.glob("module", x=1) pytestmark = pytest.mark.glob("module", x=1)
@pytest.mark.glob("class", x=2) @pytest.mark.glob("class", x=2)
class TestClass: class TestClass(object):
@pytest.mark.glob("function", x=3) @pytest.mark.glob("function", x=3)
def test_something(self): def test_something(self):
pass pass

View File

@ -16,7 +16,7 @@ def python1(request, tmpdir):
def python2(request, python1): def python2(request, python1):
return Python(request.param, python1.picklefile) return Python(request.param, python1.picklefile)
class Python: class Python(object):
def __init__(self, version, picklefile): def __init__(self, version, picklefile):
self.pythonpath = py.path.local.sysfind(version) self.pythonpath = py.path.local.sysfind(version)
if not self.pythonpath: if not self.pythonpath:

View File

@ -168,7 +168,7 @@ only have to work a bit to construct the correct arguments for pytest's
scenario1 = ('basic', {'attribute': 'value'}) scenario1 = ('basic', {'attribute': 'value'})
scenario2 = ('advanced', {'attribute': 'value2'}) scenario2 = ('advanced', {'attribute': 'value2'})
class TestSampleWithScenarios: class TestSampleWithScenarios(object):
scenarios = [scenario1, scenario2] scenarios = [scenario1, scenario2]
def test_demo1(self, attribute): def test_demo1(self, attribute):
@ -241,9 +241,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: class DB1(object):
"one database object" "one database object"
class DB2: class DB2(object):
"alternative database object" "alternative database object"
@pytest.fixture @pytest.fixture
@ -350,7 +350,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: class TestClass(object):
# 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), ],

View File

@ -4,7 +4,7 @@
def test_function(): def test_function():
pass pass
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
def test_anothermethod(self): def test_anothermethod(self):

View File

@ -107,7 +107,7 @@ This would make ``pytest`` look for tests in files that match the ``check_*
that match ``*_check``. For example, if we have:: that match ``*_check``. For example, if we have::
# content of check_myapp.py # content of check_myapp.py
class CheckMyApp: class CheckMyApp(object):
def simple_check(self): def simple_check(self):
pass pass
def complex_check(self): def complex_check(self):

View File

@ -550,7 +550,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef> self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_single_line(self): def test_single_line(self):
class A: class A(object):
a = 1 a = 1
b = 2 b = 2
> assert A.a == b, "A.a appears not to be b" > assert A.a == b, "A.a appears not to be b"
@ -564,7 +564,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef> self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_multiline(self): def test_multiline(self):
class A: class A(object):
a = 1 a = 1
b = 2 b = 2
> assert A.a == b, "A.a appears not to be b\n" \ > assert A.a == b, "A.a appears not to be b\n" \
@ -581,7 +581,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef> self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_custom_repr(self): def test_custom_repr(self):
class JSON: class JSON(object):
a = 1 a = 1
def __repr__(self): def __repr__(self):
return "This is JSON\n{\n 'foo': 'bar'\n}" return "This is JSON\n{\n 'foo': 'bar'\n}"

View File

@ -425,7 +425,7 @@ tests in a class. Here is a test module example:
import pytest import pytest
@pytest.mark.incremental @pytest.mark.incremental
class TestUserHandling: class TestUserHandling(object):
def test_login(self): def test_login(self):
pass pass
def test_modification(self): def test_modification(self):
@ -483,7 +483,7 @@ Here is an example for making a ``db`` fixture available in a directory:
# content of a/conftest.py # content of a/conftest.py
import pytest import pytest
class DB: class DB(object):
pass pass
@pytest.fixture(scope="session") @pytest.fixture(scope="session")

View File

@ -28,7 +28,7 @@ will be called ahead of running any tests::
# content of test_module.py # content of test_module.py
class TestHello: class TestHello(object):
@classmethod @classmethod
def callme(cls): def callme(cls):
print ("callme called!") print ("callme called!")
@ -39,7 +39,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: class TestOther(object):
@classmethod @classmethod
def callme(cls): def callme(cls):
print ("callme other called") print ("callme other called")

View File

@ -557,7 +557,7 @@ and instantiate an object ``app`` where we stick the already defined
import pytest import pytest
class App: class App(object):
def __init__(self, smtp): def __init__(self, smtp):
self.smtp = smtp self.smtp = smtp
@ -728,7 +728,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: class TestDirectoryInit(object):
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:
@ -791,7 +791,7 @@ self-contained implementation of this idea::
import pytest import pytest
class DB: class DB(object):
def __init__(self): def __init__(self):
self.intransaction = [] self.intransaction = []
def begin(self, name): def begin(self, name):
@ -803,7 +803,7 @@ self-contained implementation of this idea::
def db(): def db():
return DB() return DB()
class TestClass: class TestClass(object):
@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__)
@ -861,7 +861,7 @@ into a conftest.py file **without** using ``autouse``::
and then e.g. have a TestClass using it by declaring the need:: and then e.g. have a TestClass using it by declaring the need::
@pytest.mark.usefixtures("transact") @pytest.mark.usefixtures("transact")
class TestClass: class TestClass(object):
def test_method1(self): def test_method1(self):
... ...

View File

@ -24,7 +24,7 @@ resources. Here is a basic example how we could implement
a per-session Database object:: a per-session Database object::
# content of conftest.py # content of conftest.py
class Database: class Database(object):
def __init__(self): def __init__(self):
print ("database instance created") print ("database instance created")
def destroy(self): def destroy(self):

View File

@ -1,7 +1,7 @@
import textwrap import textwrap
import inspect import inspect
class Writer: class Writer(object):
def __init__(self, clsname): def __init__(self, clsname):
self.clsname = clsname self.clsname = clsname

View File

@ -111,7 +111,7 @@ to group tests logically, in classes and modules. Let's write a class
containing two tests:: containing two tests::
# content of test_class.py # content of test_class.py
class TestClass: class TestClass(object):
def test_one(self): def test_one(self):
x = "this" x = "this"
assert 'h' in x assert 'h' in x

View File

@ -98,7 +98,7 @@ You can use the ``skipif`` decorator (and any other marker) on classes::
@pytest.mark.skipif(sys.platform == 'win32', @pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows") reason="does not run on windows")
class TestPosixCalls: class TestPosixCalls(object):
def test_function(self): def test_function(self):
"will not be setup or run under 'win32' platform" "will not be setup or run under 'win32' platform"

View File

@ -110,7 +110,7 @@ If you want to disable a complete test class you
can set the class-level attribute ``disabled``. can set the class-level attribute ``disabled``.
For example, in order to avoid running some tests on Win32:: For example, in order to avoid running some tests on Win32::
class TestPosixOnly: class TestPosixOnly(object):
disabled = sys.platform == 'win32' disabled = sys.platform == 'win32'
def test_xxx(self): def test_xxx(self):

View File

@ -71,7 +71,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: class DummyDB(object):
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()

View File

@ -226,7 +226,7 @@ to all testcases you can use ``LogXML.add_global_properties``
def start_and_prepare_env(): def start_and_prepare_env():
pass pass
class TestMe: class TestMe(object):
def test_foo(self): def test_foo(self):
assert True assert True
@ -314,7 +314,7 @@ You can specify additional plugins to ``pytest.main``::
# content of myinvoke.py # content of myinvoke.py
import pytest import pytest
class MyPlugin: class MyPlugin(object):
def pytest_sessionfinish(self): def pytest_sessionfinish(self):
print("*** test run reporting finishing") print("*** test run reporting finishing")

View File

@ -8,7 +8,7 @@ import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
class TestGeneralUsage: class TestGeneralUsage(object):
def test_config_error(self, testdir): def test_config_error(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
def pytest_configure(config): def pytest_configure(config):
@ -410,7 +410,7 @@ class TestGeneralUsage:
]) ])
class TestInvocationVariants: class TestInvocationVariants(object):
def test_earlyinit(self, testdir): def test_earlyinit(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
@ -502,7 +502,7 @@ class TestInvocationVariants:
out, err = capsys.readouterr() out, err = capsys.readouterr()
def test_invoke_plugin_api(self, testdir, capsys): def test_invoke_plugin_api(self, testdir, capsys):
class MyPlugin: class MyPlugin(object):
def pytest_addoption(self, parser): def pytest_addoption(self, parser):
parser.addoption("--myopt") parser.addoption("--myopt")
@ -670,7 +670,7 @@ class TestInvocationVariants:
assert request.config.pluginmanager.hasplugin('python') assert request.config.pluginmanager.hasplugin('python')
class TestDurations: class TestDurations(object):
source = """ source = """
import time import time
frag = 0.002 frag = 0.002
@ -741,7 +741,7 @@ class TestDurations:
assert result.ret == 0 assert result.ret == 0
class TestDurationWithFixture: class TestDurationWithFixture(object):
source = """ source = """
import time import time
frag = 0.001 frag = 0.001

View File

@ -20,7 +20,7 @@ def test_code_gives_back_name_for_not_existing_file():
assert code.fullsource is None assert code.fullsource is None
def test_code_with_class(): def test_code_with_class():
class A: class A(object):
pass pass
pytest.raises(TypeError, "_pytest._code.Code(A)") pytest.raises(TypeError, "_pytest._code.Code(A)")
@ -136,7 +136,7 @@ def test_frame_getargs():
('z', {'c': 'd'})] ('z', {'c': 'd'})]
class TestExceptionInfo: class TestExceptionInfo(object):
def test_bad_getsource(self): def test_bad_getsource(self):
try: try:
@ -147,7 +147,7 @@ class TestExceptionInfo:
assert exci.getrepr() assert exci.getrepr()
class TestTracebackEntry: class TestTracebackEntry(object):
def test_getsource(self): def test_getsource(self):
try: try:

View File

@ -25,7 +25,7 @@ else:
import pytest import pytest
pytest_version_info = tuple(map(int, pytest.__version__.split(".")[:3])) pytest_version_info = tuple(map(int, pytest.__version__.split(".")[:3]))
class TWMock: class TWMock(object):
WRITE = object() WRITE = object()
def __init__(self): def __init__(self):
@ -89,7 +89,7 @@ def h():
g() g()
# #
class TestTraceback_f_g_h: class TestTraceback_f_g_h(object):
def setup_method(self, method): def setup_method(self, method):
try: try:
h() h()
@ -386,7 +386,7 @@ def test_match_raises_error(testdir):
"*AssertionError*Pattern*[123]*not found*", "*AssertionError*Pattern*[123]*not found*",
]) ])
class TestFormattedExcinfo: class TestFormattedExcinfo(object):
@pytest.fixture @pytest.fixture
def importasmod(self, request): def importasmod(self, request):
@ -472,7 +472,7 @@ raise ValueError()
pr = FormattedExcinfo() pr = FormattedExcinfo()
class FakeCode(object): class FakeCode(object):
class raw: class raw(object):
co_filename = '?' co_filename = '?'
path = '?' path = '?'

View File

@ -49,7 +49,7 @@ def test_source_from_function():
assert str(source).startswith('def test_source_str_function():') assert str(source).startswith('def test_source_str_function():')
def test_source_from_method(): def test_source_from_method():
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
source = _pytest._code.Source(TestClass().test_method) source = _pytest._code.Source(TestClass().test_method)
@ -119,7 +119,7 @@ def test_isparseable():
assert not Source(" \nif 1:\npass").isparseable() assert not Source(" \nif 1:\npass").isparseable()
assert not Source(chr(0)).isparseable() assert not Source(chr(0)).isparseable()
class TestAccesses: class TestAccesses(object):
source = Source("""\ source = Source("""\
def f(x): def f(x):
pass pass
@ -143,7 +143,7 @@ class TestAccesses:
l = [x for x in self.source] l = [x for x in self.source]
assert len(l) == 4 assert len(l) == 4
class TestSourceParsingAndCompiling: class TestSourceParsingAndCompiling(object):
source = Source("""\ source = Source("""\
def f(x): def f(x):
assert (x == assert (x ==
@ -307,7 +307,7 @@ class TestSourceParsingAndCompiling:
pytest.raises(SyntaxError, _pytest._code.compile, "lambda a,a: 0", mode='eval') pytest.raises(SyntaxError, _pytest._code.compile, "lambda a,a: 0", mode='eval')
def test_getstartingblock_singleline(): def test_getstartingblock_singleline():
class A: class A(object):
def __init__(self, *args): def __init__(self, *args):
frame = sys._getframe(1) frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement self.source = _pytest._code.Frame(frame).statement
@ -318,7 +318,7 @@ def test_getstartingblock_singleline():
assert len(l) == 1 assert len(l) == 1
def test_getstartingblock_multiline(): def test_getstartingblock_multiline():
class A: class A(object):
def __init__(self, *args): def __init__(self, *args):
frame = sys._getframe(1) frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement self.source = _pytest._code.Frame(frame).statement
@ -461,16 +461,16 @@ def test_getfslineno():
assert lineno == A_lineno assert lineno == A_lineno
assert getfslineno(3) == ("", -1) assert getfslineno(3) == ("", -1)
class B: class B(object):
pass pass
B.__name__ = "B2" B.__name__ = "B2"
assert getfslineno(B)[1] == -1 assert getfslineno(B)[1] == -1
def test_code_of_object_instance_with_call(): def test_code_of_object_instance_with_call():
class A: class A(object):
pass pass
pytest.raises(TypeError, lambda: _pytest._code.Source(A())) pytest.raises(TypeError, lambda: _pytest._code.Source(A()))
class WithCall: class WithCall(object):
def __call__(self): def __call__(self):
pass pass
@ -559,7 +559,7 @@ x = 3
""") """)
assert str(source) == "raise ValueError(\n 23\n)" assert str(source) == "raise ValueError(\n 23\n)"
class TestTry: class TestTry(object):
pytestmark = astonly pytestmark = astonly
source = """\ source = """\
try: try:
@ -586,7 +586,7 @@ else:
source = getstatement(5, self.source) source = getstatement(5, self.source)
assert str(source) == " raise KeyError()" assert str(source) == " raise KeyError()"
class TestTryFinally: class TestTryFinally(object):
source = """\ source = """\
try: try:
raise ValueError raise ValueError
@ -604,7 +604,7 @@ finally:
class TestIf: class TestIf(object):
pytestmark = astonly pytestmark = astonly
source = """\ source = """\
if 1: if 1:

View File

@ -48,7 +48,7 @@ def test_str_args_deprecated(tmpdir, testdir):
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
warnings = [] warnings = []
class Collect: class Collect(object):
def pytest_logwarning(self, message): def pytest_logwarning(self, message):
warnings.append(message) warnings.append(message)

View File

@ -20,7 +20,7 @@ class MyDocTestRunner(doctest.DocTestRunner):
example.source.strip(), got.strip(), example.want.strip())) example.source.strip(), got.strip(), example.want.strip()))
class TestApprox: class TestApprox(object):
def test_repr_string(self): def test_repr_string(self):
# for some reason in Python 2.6 it is not displaying the tolerance representation correctly # for some reason in Python 2.6 it is not displaying the tolerance representation correctly

View File

@ -12,7 +12,7 @@ from _pytest.main import (
) )
class TestModule: class TestModule(object):
def test_failing_import(self, testdir): def test_failing_import(self, testdir):
modcol = testdir.getmodulecol("import alksdjalskdjalkjals") modcol = testdir.getmodulecol("import alksdjalskdjalkjals")
pytest.raises(Collector.CollectError, modcol.collect) pytest.raises(Collector.CollectError, modcol.collect)
@ -105,10 +105,10 @@ class TestModule:
assert name not in stdout assert name not in stdout
class TestClass: class TestClass(object):
def test_class_with_init_warning(self, testdir): def test_class_with_init_warning(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class TestClass1: class TestClass1(object):
def __init__(self): def __init__(self):
pass pass
""") """)
@ -129,7 +129,7 @@ class TestClass:
def test_setup_teardown_class_as_classmethod(self, testdir): def test_setup_teardown_class_as_classmethod(self, testdir):
testdir.makepyfile(test_mod1=""" testdir.makepyfile(test_mod1="""
class TestClassMethod: class TestClassMethod(object):
@classmethod @classmethod
def setup_class(cls): def setup_class(cls):
pass pass
@ -167,7 +167,7 @@ class TestClass:
) )
class TestGenerator: class TestGenerator(object):
def test_generative_functions(self, testdir): def test_generative_functions(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def func1(arg, arg2): def func1(arg, arg2):
@ -192,7 +192,7 @@ class TestGenerator:
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def func1(arg, arg2): def func1(arg, arg2):
assert arg == arg2 assert arg == arg2
class TestGenMethods: class TestGenMethods(object):
def test_gen(self): def test_gen(self):
yield func1, 17, 3*5 yield func1, 17, 3*5
yield func1, 42, 6*7 yield func1, 42, 6*7
@ -246,7 +246,7 @@ class TestGenerator:
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def func1(arg, arg2): def func1(arg, arg2):
assert arg == arg2 assert arg == arg2
class TestGenMethods: class TestGenMethods(object):
def test_gen(self): def test_gen(self):
yield "m1", func1, 17, 3*5 yield "m1", func1, 17, 3*5
yield "m2", func1, 42, 6*7 yield "m2", func1, 42, 6*7
@ -326,7 +326,7 @@ class TestGenerator:
# has been used during collection. # has been used during collection.
o = testdir.makepyfile(""" o = testdir.makepyfile("""
setuplist = [] setuplist = []
class TestClass: class TestClass(object):
def setup_method(self, func): def setup_method(self, func):
#print "setup_method", self, func #print "setup_method", self, func
setuplist.append(self) setuplist.append(self)
@ -360,7 +360,7 @@ class TestGenerator:
assert not skipped and not failed assert not skipped and not failed
class TestFunction: class TestFunction(object):
def test_getmodulecollector(self, testdir): def test_getmodulecollector(self, testdir):
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
modcol = item.getparent(pytest.Module) modcol = item.getparent(pytest.Module)
@ -369,7 +369,7 @@ class TestFunction:
def test_function_as_object_instance_ignored(self, testdir): def test_function_as_object_instance_ignored(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class A: class A(object):
def __call__(self, tmpdir): def __call__(self, tmpdir):
0/0 0/0
@ -420,7 +420,7 @@ class TestFunction:
def test_issue213_parametrize_value_no_equal(self, testdir): def test_issue213_parametrize_value_no_equal(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class A: class A(object):
def __eq__(self, other): def __eq__(self, other):
raise ValueError("not possible") raise ValueError("not possible")
@pytest.mark.parametrize('arg', [A()]) @pytest.mark.parametrize('arg', [A()])
@ -551,11 +551,11 @@ class TestFunction:
item = testdir.getitem("def test_func(): raise ValueError") item = testdir.getitem("def test_func(): raise ValueError")
config = item.config config = item.config
class MyPlugin1: class MyPlugin1(object):
def pytest_pyfunc_call(self, pyfuncitem): def pytest_pyfunc_call(self, pyfuncitem):
raise ValueError raise ValueError
class MyPlugin2: class MyPlugin2(object):
def pytest_pyfunc_call(self, pyfuncitem): def pytest_pyfunc_call(self, pyfuncitem):
return True return True
@ -683,7 +683,7 @@ class TestFunction:
assert [x.originalname for x in items] == ['test_func', 'test_func'] assert [x.originalname for x in items] == ['test_func', 'test_func']
class TestSorting: class TestSorting(object):
def test_check_equality(self, testdir): def test_check_equality(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def test_pass(): pass def test_pass(): pass
@ -733,7 +733,7 @@ class TestSorting:
assert [item.name for item in colitems] == ['test_b', 'test_a'] assert [item.name for item in colitems] == ['test_b', 'test_a']
class TestConftestCustomization: class TestConftestCustomization(object):
def test_pytest_pycollect_module(self, testdir): def test_pytest_pycollect_module(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import pytest import pytest
@ -847,7 +847,7 @@ def test_modulecol_roundtrip(testdir):
assert modcol.name == newcol.name assert modcol.name == newcol.name
class TestTracebackCutting: class TestTracebackCutting(object):
def test_skip_simple(self): def test_skip_simple(self):
excinfo = pytest.raises(pytest.skip.Exception, 'pytest.skip("xxx")') excinfo = pytest.raises(pytest.skip.Exception, 'pytest.skip("xxx")')
assert excinfo.traceback[-1].frame.code.name == "skip" assert excinfo.traceback[-1].frame.code.name == "skip"
@ -973,7 +973,7 @@ class TestTracebackCutting:
assert filter_traceback(tb[-1]) assert filter_traceback(tb[-1])
class TestReportInfo: class TestReportInfo(object):
def test_itemreport_reportinfo(self, testdir, linecomp): def test_itemreport_reportinfo(self, testdir, linecomp):
testdir.makeconftest(""" testdir.makeconftest("""
import pytest import pytest
@ -998,7 +998,7 @@ class TestReportInfo:
def test_class_reportinfo(self, testdir): def test_class_reportinfo(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
# lineno 0 # lineno 0
class TestClass: class TestClass(object):
def test_hello(self): pass def test_hello(self): pass
""") """)
classcol = testdir.collect_by_name(modcol, "TestClass") classcol = testdir.collect_by_name(modcol, "TestClass")
@ -1033,7 +1033,7 @@ class TestReportInfo:
def check(x): def check(x):
pass pass
yield check, 3 yield check, 3
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""" """
@ -1042,7 +1042,7 @@ class TestReportInfo:
# https://github.com/pytest-dev/pytest/issues/1204 # https://github.com/pytest-dev/pytest/issues/1204
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
# lineno 0 # lineno 0
class TestClass: class TestClass(object):
def __getattr__(self, name): def __getattr__(self, name):
return "this is not an int" return "this is not an int"
@ -1064,7 +1064,7 @@ def test_customized_python_discovery(testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def check_simple(): def check_simple():
pass pass
class CheckMyApp: class CheckMyApp(object):
def check_meth(self): def check_meth(self):
pass pass
""") """)
@ -1139,7 +1139,7 @@ def test_customize_through_attributes(testdir):
return MyClass(name, parent=collector) return MyClass(name, parent=collector)
""") """)
testdir.makepyfile(""" testdir.makepyfile("""
class MyTestClass: class MyTestClass(object):
def test_hello(self): def test_hello(self):
pass pass
""") """)
@ -1153,11 +1153,11 @@ def test_customize_through_attributes(testdir):
def test_unorderable_types(testdir): def test_unorderable_types(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class TestJoinEmpty: class TestJoinEmpty(object):
pass pass
def make_test(): def make_test():
class Test: class Test(object):
pass pass
Test.__name__ = "TestFoo" Test.__name__ = "TestFoo"
return Test return Test

View File

@ -20,7 +20,7 @@ def test_getfuncargnames():
def h(arg1, arg2, arg3="hello"): pass def h(arg1, arg2, arg3="hello"): pass
assert fixtures.getfuncargnames(h) == ('arg1', 'arg2') assert fixtures.getfuncargnames(h) == ('arg1', 'arg2')
class A: class A(object):
def f(self, arg1, arg2="hello"): def f(self, arg1, arg2="hello"):
pass pass
@ -28,7 +28,7 @@ def test_getfuncargnames():
if sys.version_info < (3,0): if sys.version_info < (3,0):
assert fixtures.getfuncargnames(A.f) == ('arg1',) assert fixtures.getfuncargnames(A.f) == ('arg1',)
class TestFillFixtures: class TestFillFixtures(object):
def test_fillfuncargs_exposed(self): def test_fillfuncargs_exposed(self):
# used by oejskit, kept for compatibility # used by oejskit, kept for compatibility
assert pytest._fillfuncargs == fixtures.fillfixtures assert pytest._fillfuncargs == fixtures.fillfixtures
@ -79,7 +79,7 @@ class TestFillFixtures:
def something(request): def something(request):
return request.function.__name__ return request.function.__name__
class TestClass: class TestClass(object):
def test_method(self, something): def test_method(self, something):
assert something == "test_method" assert something == "test_method"
def test_func(something): def test_func(something):
@ -91,7 +91,7 @@ class TestFillFixtures:
def test_funcarg_lookup_classlevel(self, testdir): def test_funcarg_lookup_classlevel(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
@pytest.fixture @pytest.fixture
def something(self, request): def something(self, request):
@ -134,7 +134,7 @@ class TestFillFixtures:
def spam(): def spam():
return 'spam' return 'spam'
class TestSpam: class TestSpam(object):
@pytest.fixture @pytest.fixture
def spam(self, spam): def spam(self, spam):
@ -463,7 +463,7 @@ class TestFillFixtures:
assert result.ret == 0 assert result.ret == 0
class TestRequestBasic: class TestRequestBasic(object):
def test_request_attributes(self, testdir): def test_request_attributes(self, testdir):
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
@ -484,7 +484,7 @@ class TestRequestBasic:
def test_request_attributes_method(self, testdir): def test_request_attributes_method(self, testdir):
item, = testdir.getitems(""" item, = testdir.getitems("""
import pytest import pytest
class TestB: class TestB(object):
@pytest.fixture @pytest.fixture
def something(self, request): def something(self, request):
@ -502,7 +502,7 @@ class TestRequestBasic:
@pytest.fixture @pytest.fixture
def something(request): def something(request):
pass pass
class TestClass: class TestClass(object):
def test_method(self, something): def test_method(self, something):
pass pass
""") """)
@ -704,7 +704,7 @@ class TestRequestBasic:
def test_func(): def test_func():
pass pass
class TestClass: class TestClass(object):
@pytest.fixture(scope="class", autouse=True) @pytest.fixture(scope="class", autouse=True)
def setup_class(self): def setup_class(self):
l.append("class") l.append("class")
@ -771,7 +771,7 @@ class TestRequestBasic:
reprec = testdir.inline_run() reprec = testdir.inline_run()
reprec.assertoutcome(passed=2) reprec.assertoutcome(passed=2)
class TestRequestMarking: class TestRequestMarking(object):
def test_applymarker(self, testdir): def test_applymarker(self, testdir):
item1,item2 = testdir.getitems(""" item1,item2 = testdir.getitems("""
import pytest import pytest
@ -779,7 +779,7 @@ class TestRequestMarking:
@pytest.fixture @pytest.fixture
def something(request): def something(request):
pass pass
class TestClass: class TestClass(object):
def test_func1(self, something): def test_func1(self, something):
pass pass
def test_func2(self, something): def test_func2(self, something):
@ -831,7 +831,7 @@ class TestRequestMarking:
reprec = testdir.inline_run() reprec = testdir.inline_run()
reprec.assertoutcome(passed=2) reprec.assertoutcome(passed=2)
class TestRequestCachedSetup: class TestRequestCachedSetup(object):
def test_request_cachedsetup_defaultmodule(self, testdir): def test_request_cachedsetup_defaultmodule(self, testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
mysetup = ["hello",].pop mysetup = ["hello",].pop
@ -844,7 +844,7 @@ class TestRequestCachedSetup:
def test_func1(something): def test_func1(something):
assert something == "hello" assert something == "hello"
class TestClass: class TestClass(object):
def test_func1a(self, something): def test_func1a(self, something):
assert something == "hello" assert something == "hello"
""") """)
@ -862,7 +862,7 @@ class TestRequestCachedSetup:
assert something == "hello3" assert something == "hello3"
def test_func2(something): def test_func2(something):
assert something == "hello2" assert something == "hello2"
class TestClass: class TestClass(object):
def test_func1a(self, something): def test_func1a(self, something):
assert something == "hello" assert something == "hello"
def test_func2b(self, something): def test_func2b(self, something):
@ -996,7 +996,7 @@ class TestRequestCachedSetup:
"*ZeroDivisionError*", "*ZeroDivisionError*",
]) ])
class TestFixtureUsages: class TestFixtureUsages(object):
def test_noargfixturedec(self, testdir): def test_noargfixturedec(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -1138,7 +1138,7 @@ class TestFixtureUsages:
def test_factory_setup_as_classes_fails(self, testdir): def test_factory_setup_as_classes_fails(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class arg1: class arg1(object):
def __init__(self, request): def __init__(self, request):
self.x = 1 self.x = 1
arg1 = pytest.fixture()(arg1) arg1 = pytest.fixture()(arg1)
@ -1172,7 +1172,7 @@ class TestFixtureUsages:
request.cls.hello = "world" request.cls.hello = "world"
l.append(1) l.append(1)
class TestClass: class TestClass(object):
def test_one(self): def test_one(self):
assert self.hello == "world" assert self.hello == "world"
assert len(l) == 1 assert len(l) == 1
@ -1198,7 +1198,7 @@ class TestFixtureUsages:
""") """)
testdir.makepyfile(""" testdir.makepyfile("""
class TestClass: class TestClass(object):
def test_one(self): def test_one(self):
assert self.hello == "world" assert self.hello == "world"
def test_two(self): def test_two(self):
@ -1217,7 +1217,7 @@ class TestFixtureUsages:
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
@pytest.fixture @pytest.fixture
def setup1(self, request): def setup1(self, request):
assert self == request.instance assert self == request.instance
@ -1256,7 +1256,7 @@ class TestFixtureUsages:
assert l == [1,2, 10,20] assert l == [1,2, 10,20]
class TestFixtureManagerParseFactories: class TestFixtureManagerParseFactories(object):
@pytest.fixture @pytest.fixture
def testdir(self, request): def testdir(self, request):
@ -1280,7 +1280,7 @@ class TestFixtureManagerParseFactories:
def test_parsefactories_evil_objects_issue214(self, testdir): def test_parsefactories_evil_objects_issue214(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class A: class A(object):
def __call__(self): def __call__(self):
pass pass
def __getattr__(self, name): def __getattr__(self, name):
@ -1311,7 +1311,7 @@ class TestFixtureManagerParseFactories:
@pytest.fixture @pytest.fixture
def hello(request): def hello(request):
return "module" return "module"
class TestClass: class TestClass(object):
@pytest.fixture @pytest.fixture
def hello(self, request): def hello(self, request):
return "class" return "class"
@ -1360,7 +1360,7 @@ class TestFixtureManagerParseFactories:
reprec.assertoutcome(passed=2) reprec.assertoutcome(passed=2)
class TestAutouseDiscovery: class TestAutouseDiscovery(object):
@pytest.fixture @pytest.fixture
def testdir(self, testdir): def testdir(self, testdir):
@ -1402,14 +1402,14 @@ class TestAutouseDiscovery:
def test_two_classes_separated_autouse(self, testdir): def test_two_classes_separated_autouse(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestA: class TestA(object):
l = [] l = []
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup1(self): def setup1(self):
self.l.append(1) self.l.append(1)
def test_setup1(self): def test_setup1(self):
assert self.l == [1] assert self.l == [1]
class TestB: class TestB(object):
l = [] l = []
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup2(self): def setup2(self):
@ -1423,7 +1423,7 @@ class TestAutouseDiscovery:
def test_setup_at_classlevel(self, testdir): def test_setup_at_classlevel(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def permethod(self, request): def permethod(self, request):
request.instance.funcname = request.function.__name__ request.instance.funcname = request.function.__name__
@ -1505,13 +1505,13 @@ class TestAutouseDiscovery:
def test_x(): def test_x():
assert l == ["module"] assert l == ["module"]
class TestA: class TestA(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def append2(self): def append2(self):
l.append("A") l.append("A")
def test_hello(self): def test_hello(self):
assert l == ["module", "module", "A"], l assert l == ["module", "module", "A"], l
class TestA2: class TestA2(object):
def test_world(self): def test_world(self):
assert l == ["module", "module", "A", "module"], l assert l == ["module", "module", "A", "module"], l
""") """)
@ -1519,7 +1519,7 @@ class TestAutouseDiscovery:
reprec.assertoutcome(passed=3) reprec.assertoutcome(passed=3)
class TestAutouseManagement: class TestAutouseManagement(object):
def test_autouse_conftest_mid_directory(self, testdir): def test_autouse_conftest_mid_directory(self, testdir):
pkgdir = testdir.mkpydir("xyz123") pkgdir = testdir.mkpydir("xyz123")
pkgdir.join("conftest.py").write(_pytest._code.Source(""" pkgdir.join("conftest.py").write(_pytest._code.Source("""
@ -1654,10 +1654,10 @@ class TestAutouseManagement:
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
def test_1(self): def test_1(self):
pass pass
class TestClass2: class TestClass2(object):
def test_2(self): def test_2(self):
pass pass
""") """)
@ -1682,7 +1682,7 @@ class TestAutouseManagement:
def mappend(): def mappend():
l.append(1) l.append(1)
class TestHallo: class TestHallo(object):
def test_method(self): def test_method(self):
assert l == [1,3,2] assert l == [1,3,2]
""") """)
@ -1696,7 +1696,7 @@ class TestAutouseManagement:
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
if metafunc.cls is not None: if metafunc.cls is not None:
metafunc.parametrize("item", [1,2], scope="class") metafunc.parametrize("item", [1,2], scope="class")
class TestClass: class TestClass(object):
@pytest.fixture(scope="class", autouse=True) @pytest.fixture(scope="class", autouse=True)
def addteardown(self, item, request): def addteardown(self, item, request):
l.append("setup-%d" % item) l.append("setup-%d" % item)
@ -1756,7 +1756,7 @@ class TestAutouseManagement:
reprec.assertoutcome(passed=2) reprec.assertoutcome(passed=2)
class TestFixtureMarker: class TestFixtureMarker(object):
def test_parametrize(self, testdir): def test_parametrize(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -1822,7 +1822,7 @@ class TestFixtureMarker:
def test_2(arg): def test_2(arg):
assert arg == 1 assert arg == 1
assert len(l) == 1 assert len(l) == 1
class TestClass: class TestClass(object):
def test3(self, arg): def test3(self, arg):
assert arg == 1 assert arg == 1
assert len(l) == 1 assert len(l) == 1
@ -1916,7 +1916,7 @@ class TestFixtureMarker:
def test_2(arg): def test_2(arg):
assert arg == 1 assert arg == 1
assert len(l) == 1 assert len(l) == 1
class TestClass: class TestClass(object):
def test3(self, arg): def test3(self, arg):
assert arg == 1 assert arg == 1
assert len(l) == 1 assert len(l) == 1
@ -2135,12 +2135,12 @@ class TestFixtureMarker:
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestClass2: class TestClass2(object):
def test_1(self): def test_1(self):
pass pass
def test_2(self): def test_2(self):
pass pass
class TestClass: class TestClass(object):
def test_3(self): def test_3(self):
pass pass
""") """)
@ -2213,7 +2213,7 @@ class TestFixtureMarker:
l = [] l = []
class TestClass: class TestClass(object):
@classmethod @classmethod
@pytest.fixture(scope="class", autouse=True) @pytest.fixture(scope="class", autouse=True)
def setup1(self, request, param1): def setup1(self, request, param1):
@ -2273,7 +2273,7 @@ class TestFixtureMarker:
testpath = testdir.makepyfile(""" testpath = testdir.makepyfile("""
import pytest import pytest
class Box: class Box(object):
value = 0 value = 0
@pytest.fixture(scope='class') @pytest.fixture(scope='class')
@ -2284,11 +2284,11 @@ class TestFixtureMarker:
def test_a(a): def test_a(a):
assert a == 1 assert a == 1
class Test1: class Test1(object):
def test_b(self, a): def test_b(self, a):
assert a == 2 assert a == 2
class Test2: class Test2(object):
def test_c(self, a): def test_c(self, a):
assert a == 3""") assert a == 3""")
reprec = testdir.inline_run(testpath) reprec = testdir.inline_run(testpath)
@ -2402,11 +2402,11 @@ class TestFixtureMarker:
request.addfinalizer(lambda: l.append("fin %s" % request.param)) request.addfinalizer(lambda: l.append("fin %s" % request.param))
return request.param return request.param
class TestGreetings: class TestGreetings(object):
def test_hello(self, human): def test_hello(self, human):
l.append("test_hello") l.append("test_hello")
class TestMetrics: class TestMetrics(object):
def test_name(self, human): def test_name(self, human):
l.append("test_name") l.append("test_name")
@ -2499,7 +2499,7 @@ class TestFixtureMarker:
'*test_foo*beta*']) '*test_foo*beta*'])
class TestRequestScopeAccess: class TestRequestScopeAccess(object):
pytestmark = pytest.mark.parametrize(("scope", "ok", "error"),[ pytestmark = pytest.mark.parametrize(("scope", "ok", "error"),[
["session", "", "fspath class function module"], ["session", "", "fspath class function module"],
["module", "module fspath", "cls function"], ["module", "module fspath", "cls function"],
@ -2543,7 +2543,7 @@ class TestRequestScopeAccess:
reprec = testdir.inline_run() reprec = testdir.inline_run()
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
class TestErrors: class TestErrors(object):
def test_subfactory_missing_funcarg(self, testdir): def test_subfactory_missing_funcarg(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -2607,7 +2607,7 @@ class TestErrors:
"*1 error*", "*1 error*",
]) ])
class TestShowFixtures: class TestShowFixtures(object):
def test_funcarg_compat(self, testdir): def test_funcarg_compat(self, testdir):
config = testdir.parseconfigure("--funcargs") config = testdir.parseconfigure("--funcargs")
assert config.option.showfixtures assert config.option.showfixtures
@ -2770,7 +2770,7 @@ class TestShowFixtures:
@pytest.mark.parametrize('flavor', ['fixture', 'yield_fixture']) @pytest.mark.parametrize('flavor', ['fixture', 'yield_fixture'])
class TestContextManagerFixtureFuncs: class TestContextManagerFixtureFuncs(object):
def test_simple(self, testdir, flavor): def test_simple(self, testdir, flavor):
testdir.makepyfile(""" testdir.makepyfile("""
@ -2877,7 +2877,7 @@ class TestContextManagerFixtureFuncs:
result = testdir.runpytest("-s") result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("*mew*") result.stdout.fnmatch_lines("*mew*")
class TestParameterizedSubRequest: class TestParameterizedSubRequest(object):
def test_call_from_fixture(self, testdir): def test_call_from_fixture(self, testdir):
testfile = testdir.makepyfile(""" testfile = testdir.makepyfile("""
import pytest import pytest

View File

@ -3,7 +3,7 @@ from _pytest import python
from _pytest import runner from _pytest import runner
class TestOEJSKITSpecials: class TestOEJSKITSpecials(object):
def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage
testdir.makeconftest(""" testdir.makeconftest("""
import pytest import pytest
@ -19,7 +19,7 @@ class TestOEJSKITSpecials:
@pytest.fixture @pytest.fixture
def arg1(request): def arg1(request):
return 42 return 42
class MyClass: class MyClass(object):
pass pass
""") """)
# this hook finds funcarg factories # this hook finds funcarg factories
@ -48,7 +48,7 @@ class TestOEJSKITSpecials:
@pytest.fixture @pytest.fixture
def arg1(request): def arg1(request):
return 42 return 42
class MyClass: class MyClass(object):
pass pass
""") """)
# this hook finds funcarg factories # this hook finds funcarg factories
@ -76,7 +76,7 @@ def test_wrapped_getfslineno():
fs2, lineno2 = python.getfslineno(wrap) fs2, lineno2 = python.getfslineno(wrap)
assert lineno > lineno2, "getfslineno does not unwrap correctly" assert lineno > lineno2, "getfslineno does not unwrap correctly"
class TestMockDecoration: class TestMockDecoration(object):
def test_wrapped_getfuncargnames(self): def test_wrapped_getfuncargnames(self):
from _pytest.compat import getfuncargnames from _pytest.compat import getfuncargnames
@ -207,7 +207,7 @@ class TestMockDecoration:
@patch('os.getcwd') @patch('os.getcwd')
@patch('os.path') @patch('os.path')
@mark.slow @mark.slow
class TestSimple: class TestSimple(object):
def test_simple_thing(self, mock_path, mock_getcwd): def test_simple_thing(self, mock_path, mock_getcwd):
pass pass
""") """)
@ -215,7 +215,7 @@ class TestMockDecoration:
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
class TestReRunTests: class TestReRunTests(object):
def test_rerun(self, testdir): def test_rerun(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
from _pytest.runner import runtestprotocol from _pytest.runner import runtestprotocol
@ -251,7 +251,7 @@ def test_pytestconfig_is_session_scoped():
assert pytestconfig._pytestfixturefunction.scope == "session" assert pytestconfig._pytestfixturefunction.scope == "session"
class TestNoselikeTestAttribute: class TestNoselikeTestAttribute(object):
def test_module_with_global_test(self, testdir): def test_module_with_global_test(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
__test__ = False __test__ = False
@ -270,7 +270,7 @@ class TestNoselikeTestAttribute:
pass pass
test_func.__test__ = False test_func.__test__ = False
class TestSome: class TestSome(object):
__test__ = False __test__ = False
def test_method(self): def test_method(self):
pass pass
@ -328,7 +328,7 @@ class TestNoselikeTestAttribute:
@pytest.mark.issue351 @pytest.mark.issue351
class TestParameterize: class TestParameterize(object):
def test_idfn_marker(self, testdir): def test_idfn_marker(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""

View File

@ -13,12 +13,12 @@ from hypothesis import strategies
PY3 = sys.version_info >= (3, 0) PY3 = sys.version_info >= (3, 0)
class TestMetafunc: class TestMetafunc(object):
def Metafunc(self, func): def Metafunc(self, func):
# the unit tests of this class check if things work correctly # the unit tests of this class check if things work correctly
# on the funcarg level, so we don't need a full blown # on the funcarg level, so we don't need a full blown
# initiliazation # initiliazation
class FixtureInfo: class FixtureInfo(object):
name2fixturedefs = None name2fixturedefs = None
def __init__(self, names): def __init__(self, names):
@ -68,7 +68,7 @@ class TestMetafunc:
def func(arg1): pass def func(arg1): pass
metafunc = self.Metafunc(func) metafunc = self.Metafunc(func)
class obj: pass class obj(object): pass
metafunc.addcall(param=obj) metafunc.addcall(param=obj)
metafunc.addcall(param=obj) metafunc.addcall(param=obj)
@ -83,7 +83,7 @@ class TestMetafunc:
metafunc = self.Metafunc(func) metafunc = self.Metafunc(func)
class obj: pass class obj(object): pass
metafunc.addcall(funcargs={"x": 2}) metafunc.addcall(funcargs={"x": 2})
metafunc.addcall(funcargs={"x": 3}) metafunc.addcall(funcargs={"x": 3})
@ -150,7 +150,7 @@ class TestMetafunc:
def func(x, y): pass def func(x, y): pass
metafunc = self.Metafunc(func) metafunc = self.Metafunc(func)
class A: class A(object):
pass pass
metafunc.parametrize("x", [A(), A()]) metafunc.parametrize("x", [A(), A()])
@ -601,7 +601,7 @@ class TestMetafunc:
pytestmark = pytest.mark.parametrize("x", [1,2]) pytestmark = pytest.mark.parametrize("x", [1,2])
def test_func(x): def test_func(x):
assert 0, x assert 0, x
class TestClass: class TestClass(object):
pytestmark = pytest.mark.parametrize("y", [3,4]) pytestmark = pytest.mark.parametrize("y", [3,4])
def test_meth(self, x, y): def test_meth(self, x, y):
assert 0, x assert 0, x
@ -672,7 +672,7 @@ class TestMetafunc:
assert fixtures._format_args(function4) == "(arg1, *args, **kwargs)" assert fixtures._format_args(function4) == "(arg1, *args, **kwargs)"
class TestMetafuncFunctional: class TestMetafuncFunctional(object):
def test_attributes(self, testdir): def test_attributes(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
# assumes that generate/provide runs in the same process # assumes that generate/provide runs in the same process
@ -691,7 +691,7 @@ class TestMetafuncFunctional:
assert metafunc.function == test_function assert metafunc.function == test_function
assert metafunc.cls is None assert metafunc.cls is None
class TestClass: class TestClass(object):
def test_method(self, metafunc, pytestconfig): def test_method(self, metafunc, pytestconfig):
assert metafunc.config == pytestconfig assert metafunc.config == pytestconfig
assert metafunc.module.__name__ == __name__ assert metafunc.module.__name__ == __name__
@ -716,7 +716,7 @@ class TestMetafuncFunctional:
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
metafunc.addcall(funcargs=dict(arg1=1, arg2=1)) metafunc.addcall(funcargs=dict(arg1=1, arg2=1))
class TestClass: class TestClass(object):
def test_myfunc(self, arg1, arg2): def test_myfunc(self, arg1, arg2):
assert arg1 == arg2 assert arg1 == arg2
""") """)
@ -756,7 +756,7 @@ class TestMetafuncFunctional:
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
assert 'xyz' not in metafunc.fixturenames assert 'xyz' not in metafunc.fixturenames
class TestHello: class TestHello(object):
def test_hello(xyz): def test_hello(xyz):
pass pass
""") """)
@ -782,7 +782,7 @@ class TestMetafuncFunctional:
def arg2(request): def arg2(request):
return request.param[1] return request.param[1]
class TestClass: class TestClass(object):
def test_myfunc(self, arg1, arg2): def test_myfunc(self, arg1, arg2):
assert arg1 == arg2 assert arg1 == arg2
""") """)
@ -795,7 +795,7 @@ class TestMetafuncFunctional:
def test_generate_tests_in_class(self, testdir): def test_generate_tests_in_class(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class TestClass: class TestClass(object):
def pytest_generate_tests(self, metafunc): def pytest_generate_tests(self, metafunc):
metafunc.addcall(funcargs={'hello': 'world'}, id="hello") metafunc.addcall(funcargs={'hello': 'world'}, id="hello")
@ -814,7 +814,7 @@ class TestMetafuncFunctional:
metafunc.addcall({'arg1': 10}) metafunc.addcall({'arg1': 10})
metafunc.addcall({'arg1': 20}) metafunc.addcall({'arg1': 20})
class TestClass: class TestClass(object):
def test_func(self, arg1): def test_func(self, arg1):
assert not hasattr(self, 'x') assert not hasattr(self, 'x')
self.x = 1 self.x = 1
@ -831,7 +831,7 @@ class TestMetafuncFunctional:
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
metafunc.addcall({'arg1': 1}) metafunc.addcall({'arg1': 1})
class TestClass: class TestClass(object):
def test_method(self, arg1): def test_method(self, arg1):
assert arg1 == self.val assert arg1 == self.val
def setup_method(self, func): def setup_method(self, func):
@ -1117,7 +1117,7 @@ class TestMetafuncFunctional:
assert expectederror in failures[0].longrepr.reprcrash.message assert expectederror in failures[0].longrepr.reprcrash.message
class TestMetafuncFunctionalAuto: class TestMetafuncFunctionalAuto(object):
""" """
Tests related to automatically find out the correct scope for parametrized tests (#1832). Tests related to automatically find out the correct scope for parametrized tests (#1832).
""" """
@ -1236,7 +1236,7 @@ class TestMetafuncFunctionalAuto:
assert output.count('preparing foo-3') == 1 assert output.count('preparing foo-3') == 1
class TestMarkersWithParametrization: class TestMarkersWithParametrization(object):
pytestmark = pytest.mark.issue308 pytestmark = pytest.mark.issue308
def test_simple_mark(self, testdir): def test_simple_mark(self, testdir):
s = """ s = """

View File

@ -2,7 +2,7 @@ import pytest
import sys import sys
class TestRaises: class TestRaises(object):
def test_raises(self): def test_raises(self):
source = "int('qwe')" source = "int('qwe')"
excinfo = pytest.raises(ValueError, source) excinfo = pytest.raises(ValueError, source)
@ -20,7 +20,7 @@ class TestRaises:
pytest.raises(ValueError, int, 'hello') pytest.raises(ValueError, int, 'hello')
def test_raises_callable_no_exception(self): def test_raises_callable_no_exception(self):
class A: class A(object):
def __call__(self): def __call__(self):
pass pass
try: try:

View File

@ -69,7 +69,7 @@ class FilesCompleter(object):
completion += [f + '/' for f in anticomp] completion += [f + '/' for f in anticomp]
return completion return completion
class TestArgComplete: class TestArgComplete(object):
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')") @pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
def test_compare_with_compgen(self): def test_compare_with_compgen(self):
from _pytest._argcomplete import FastFilesCompleter from _pytest._argcomplete import FastFilesCompleter

View File

@ -25,7 +25,7 @@ def mock_config():
return Config() return Config()
class TestImportHookInstallation: class TestImportHookInstallation(object):
@pytest.mark.parametrize('initial_conftest', [True, False]) @pytest.mark.parametrize('initial_conftest', [True, False])
@pytest.mark.parametrize('mode', ['plain', 'rewrite']) @pytest.mark.parametrize('mode', ['plain', 'rewrite'])
@ -159,7 +159,7 @@ class TestImportHookInstallation:
plugin_state = "{plugin_state}" plugin_state = "{plugin_state}"
class DummyDistInfo: class DummyDistInfo(object):
project_name = 'spam' project_name = 'spam'
version = '1.0' version = '1.0'
@ -174,7 +174,7 @@ class TestImportHookInstallation:
'hampkg/__init__.py'] 'hampkg/__init__.py']
return [] return []
class DummyEntryPoint: class DummyEntryPoint(object):
name = 'spam' name = 'spam'
module_name = 'spam.py' module_name = 'spam.py'
attrs = () attrs = ()
@ -257,7 +257,7 @@ class TestImportHookInstallation:
'pytest_tests_internal_non_existing2') 'pytest_tests_internal_non_existing2')
class TestBinReprIntegration: class TestBinReprIntegration(object):
def test_pytest_assertrepr_compare_called(self, testdir): def test_pytest_assertrepr_compare_called(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
@ -288,7 +288,7 @@ def callequal(left, right, verbose=False):
return plugin.pytest_assertrepr_compare(config, '==', left, right) return plugin.pytest_assertrepr_compare(config, '==', left, right)
class TestAssert_reprcompare: class TestAssert_reprcompare(object):
def test_different_types(self): def test_different_types(self):
assert callequal([0, 1], 'foo') is None assert callequal([0, 1], 'foo') is None
@ -442,7 +442,7 @@ class TestAssert_reprcompare:
assert len(expl) > 1 assert len(expl) > 1
def test_list_bad_repr(self): def test_list_bad_repr(self):
class A: class A(object):
def __repr__(self): def __repr__(self):
raise ValueError(42) raise ValueError(42)
expl = callequal([], [A()]) expl = callequal([], [A()])
@ -501,7 +501,7 @@ class TestAssert_reprcompare:
assert msg assert msg
class TestFormatExplanation: class TestFormatExplanation(object):
def test_special_chars_full(self, testdir): def test_special_chars_full(self, testdir):
# Issue 453, for the bug this would raise IndexError # Issue 453, for the bug this would raise IndexError
@ -593,7 +593,7 @@ class TestFormatExplanation:
assert util.format_explanation(expl) == res assert util.format_explanation(expl) == res
class TestTruncateExplanation: class TestTruncateExplanation(object):
""" Confirm assertion output is truncated as expected """ """ Confirm assertion output is truncated as expected """

View File

@ -57,7 +57,7 @@ def getmsg(f, extra_ns=None, must_pass=False):
pytest.fail("function didn't raise at all") pytest.fail("function didn't raise at all")
class TestAssertionRewrite: class TestAssertionRewrite(object):
def test_place_initial_imports(self): def test_place_initial_imports(self):
s = """'Doc string'\nother = stuff""" s = """'Doc string'\nother = stuff"""
@ -333,7 +333,7 @@ class TestAssertionRewrite:
@pytest.mark.skipif("sys.version_info < (3,5)") @pytest.mark.skipif("sys.version_info < (3,5)")
def test_at_operator_issue1290(self, testdir): def test_at_operator_issue1290(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class Matrix: class Matrix(object):
def __init__(self, num): def __init__(self, num):
self.num = num self.num = num
def __matmul__(self, other): def __matmul__(self, other):
@ -515,7 +515,7 @@ class TestAssertionRewrite:
assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0] assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0]
class TestRewriteOnImport: class TestRewriteOnImport(object):
def test_pycache_is_a_file(self, testdir): def test_pycache_is_a_file(self, testdir):
testdir.tmpdir.join("__pycache__").write("Hello") testdir.tmpdir.join("__pycache__").write("Hello")
@ -884,7 +884,7 @@ class TestAssertionRewriteHookDetails(object):
""" """
path = testdir.mkpydir("foo") path = testdir.mkpydir("foo")
path.join("test_foo.py").write(_pytest._code.Source(""" path.join("test_foo.py").write(_pytest._code.Source("""
class Test: class Test(object):
def test_foo(self): def test_foo(self):
import pkgutil import pkgutil
data = pkgutil.get_data('foo.test_foo', 'data.txt') data = pkgutil.get_data('foo.test_foo', 'data.txt')
@ -912,7 +912,7 @@ def test_issue731(testdir):
assert 'unbalanced braces' not in result.stdout.str() assert 'unbalanced braces' not in result.stdout.str()
class TestIssue925(): class TestIssue925(object):
def test_simple_case(self, testdir): def test_simple_case(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def test_ternary_display(): def test_ternary_display():

View File

@ -7,7 +7,7 @@ import shutil
pytest_plugins = "pytester", pytest_plugins = "pytester",
class TestNewAPI: class TestNewAPI(object):
def test_config_cache_makedir(self, testdir): def test_config_cache_makedir(self, testdir):
testdir.makeini("[pytest]") testdir.makeini("[pytest]")
config = testdir.parseconfigure() config = testdir.parseconfigure()
@ -129,7 +129,7 @@ def test_cache_show(testdir):
]) ])
class TestLastFailed: class TestLastFailed(object):
def test_lastfailed_usecase(self, testdir, monkeypatch): def test_lastfailed_usecase(self, testdir, monkeypatch):
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1) monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)

View File

@ -55,7 +55,7 @@ def StdCapture(out=True, err=True, in_=True):
return capture.MultiCapture(out, err, in_, Capture=capture.SysCapture) return capture.MultiCapture(out, err, in_, Capture=capture.SysCapture)
class TestCaptureManager: class TestCaptureManager(object):
def test_getmethod_default_no_fd(self, monkeypatch): def test_getmethod_default_no_fd(self, monkeypatch):
from _pytest.capture import pytest_addoption from _pytest.capture import pytest_addoption
from _pytest.config import Parser from _pytest.config import Parser
@ -154,7 +154,7 @@ def test_collect_capturing(testdir):
]) ])
class TestPerTestCapturing: class TestPerTestCapturing(object):
def test_capture_and_fixtures(self, testdir): def test_capture_and_fixtures(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def setup_module(mod): def setup_module(mod):
@ -275,7 +275,7 @@ class TestPerTestCapturing:
]) ])
class TestLoggingInteraction: class TestLoggingInteraction(object):
def test_logging_stream_ownership(self, testdir): def test_logging_stream_ownership(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def test_logging(): def test_logging():
@ -395,7 +395,7 @@ class TestLoggingInteraction:
assert 'operation on closed file' not in result.stderr.str() assert 'operation on closed file' not in result.stderr.str()
class TestCaptureFixture: class TestCaptureFixture(object):
@pytest.mark.parametrize("opt", [[], ["-s"]]) @pytest.mark.parametrize("opt", [[], ["-s"]])
def test_std_functional(self, testdir, opt): def test_std_functional(self, testdir, opt):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
@ -622,7 +622,7 @@ def test_error_during_readouterr(testdir):
]) ])
class TestTextIO: class TestTextIO(object):
def test_text(self): def test_text(self):
f = capture.TextIO() f = capture.TextIO()
f.write("hello") f.write("hello")
@ -737,7 +737,7 @@ def lsof_check():
assert len2 < len1 + 3, out2 assert len2 < len1 + 3, out2
class TestFDCapture: class TestFDCapture(object):
pytestmark = needsosdup pytestmark = needsosdup
def test_simple(self, tmpfile): def test_simple(self, tmpfile):
@ -832,7 +832,7 @@ def saved_fd(fd):
os.close(new_fd) os.close(new_fd)
class TestStdCapture: class TestStdCapture(object):
captureclass = staticmethod(StdCapture) captureclass = staticmethod(StdCapture)
@contextlib.contextmanager @contextlib.contextmanager
@ -990,7 +990,7 @@ class TestStdCaptureFD(TestStdCapture):
cap.stop_capturing() cap.stop_capturing()
class TestStdCaptureFDinvalidFD: class TestStdCaptureFDinvalidFD(object):
pytestmark = needsosdup pytestmark = needsosdup
def test_stdcapture_fd_invalid_fd(self, testdir): def test_stdcapture_fd_invalid_fd(self, testdir):

View File

@ -2,7 +2,7 @@ import pytest, py
from _pytest.main import Session, EXIT_NOTESTSCOLLECTED from _pytest.main import Session, EXIT_NOTESTSCOLLECTED
class TestCollector: class TestCollector(object):
def test_collect_versus_item(self): def test_collect_versus_item(self):
from pytest import Collector, Item from pytest import Collector, Item
assert not issubclass(Collector, Item) assert not issubclass(Collector, Item)
@ -50,7 +50,7 @@ class TestCollector:
def test_getparent(self, testdir): def test_getparent(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
class TestClass: class TestClass(object):
def test_foo(): def test_foo():
pass pass
""") """)
@ -88,7 +88,7 @@ class TestCollector:
def test_can_skip_class_with_test_attr(self, testdir): def test_can_skip_class_with_test_attr(self, testdir):
"""Assure test class is skipped when using `__test__=False` (See #2007).""" """Assure test class is skipped when using `__test__=False` (See #2007)."""
testdir.makepyfile(""" testdir.makepyfile("""
class TestFoo(): class TestFoo(object):
__test__ = False __test__ = False
def __init__(self): def __init__(self):
pass pass
@ -101,7 +101,7 @@ class TestCollector:
'*no tests ran in*', '*no tests ran in*',
]) ])
class TestCollectFS: class TestCollectFS(object):
def test_ignored_certain_directories(self, testdir): def test_ignored_certain_directories(self, testdir):
tmpdir = testdir.tmpdir tmpdir = testdir.tmpdir
tmpdir.ensure("build", 'test_notfound.py') tmpdir.ensure("build", 'test_notfound.py')
@ -163,11 +163,11 @@ class TestCollectFS:
assert [x.name for x in items] == ['test_%s' % dirname] assert [x.name for x in items] == ['test_%s' % dirname]
class TestCollectPluginHookRelay: class TestCollectPluginHookRelay(object):
def test_pytest_collect_file(self, testdir): def test_pytest_collect_file(self, testdir):
wascalled = [] wascalled = []
class Plugin: class Plugin(object):
def pytest_collect_file(self, path, parent): def pytest_collect_file(self, path, parent):
if not path.basename.startswith("."): if not path.basename.startswith("."):
# Ignore hidden files, e.g. .testmondata. # Ignore hidden files, e.g. .testmondata.
@ -181,7 +181,7 @@ class TestCollectPluginHookRelay:
def test_pytest_collect_directory(self, testdir): def test_pytest_collect_directory(self, testdir):
wascalled = [] wascalled = []
class Plugin: class Plugin(object):
def pytest_collect_directory(self, path, parent): def pytest_collect_directory(self, path, parent):
wascalled.append(path.basename) wascalled.append(path.basename)
@ -192,7 +192,7 @@ class TestCollectPluginHookRelay:
assert "world" in wascalled assert "world" in wascalled
class TestPrunetraceback: class TestPrunetraceback(object):
def test_custom_repr_failure(self, testdir): def test_custom_repr_failure(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
@ -238,7 +238,7 @@ class TestPrunetraceback:
]) ])
class TestCustomConftests: class TestCustomConftests(object):
def test_ignore_collect_path(self, testdir): def test_ignore_collect_path(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
def pytest_ignore_collect(path, config): def pytest_ignore_collect(path, config):
@ -333,7 +333,7 @@ class TestCustomConftests:
"*test_x*" "*test_x*"
]) ])
class TestSession: class TestSession(object):
def test_parsearg(self, testdir): def test_parsearg(self, testdir):
p = testdir.makepyfile("def test_func(): pass") p = testdir.makepyfile("def test_func(): pass")
subdir = testdir.mkdir("sub") subdir = testdir.mkdir("sub")
@ -391,7 +391,7 @@ class TestSession:
def test_collect_protocol_method(self, testdir): def test_collect_protocol_method(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""") """)
@ -490,7 +490,7 @@ class TestSession:
def test_find_byid_without_instance_parents(self, testdir): def test_find_byid_without_instance_parents(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""") """)
@ -500,7 +500,7 @@ class TestSession:
item, = items item, = items
assert item.nodeid.endswith("TestClass::()::test_method") assert item.nodeid.endswith("TestClass::()::test_method")
class Test_getinitialnodes: class Test_getinitialnodes(object):
def test_global_file(self, testdir, tmpdir): def test_global_file(self, testdir, tmpdir):
x = tmpdir.ensure("x.py") x = tmpdir.ensure("x.py")
with tmpdir.as_cwd(): with tmpdir.as_cwd():
@ -527,7 +527,7 @@ class Test_getinitialnodes:
for col in col.listchain(): for col in col.listchain():
assert col.config is config assert col.config is config
class Test_genitems: class Test_genitems(object):
def test_check_collect_hashes(self, testdir): def test_check_collect_hashes(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def test_1(): def test_1():
@ -550,7 +550,7 @@ class Test_genitems:
def testone(): def testone():
pass pass
class TestX: class TestX(object):
def testmethod_one(self): def testmethod_one(self):
pass pass
@ -583,11 +583,11 @@ class Test_genitems:
python_functions = *_test test python_functions = *_test test
""") """)
p = testdir.makepyfile(''' p = testdir.makepyfile('''
class MyTestSuite: class MyTestSuite(object):
def x_test(self): def x_test(self):
pass pass
class TestCase: class TestCase(object):
def test_y(self): def test_y(self):
pass pass
''') ''')
@ -602,7 +602,7 @@ def test_matchnodes_two_collections_same_file(testdir):
def pytest_configure(config): def pytest_configure(config):
config.pluginmanager.register(Plugin2()) config.pluginmanager.register(Plugin2())
class Plugin2: class Plugin2(object):
def pytest_collect_file(self, path, parent): def pytest_collect_file(self, path, parent):
if path.ext == ".abc": if path.ext == ".abc":
return MyFile2(path, parent) return MyFile2(path, parent)
@ -634,7 +634,7 @@ def test_matchnodes_two_collections_same_file(testdir):
]) ])
class TestNodekeywords: class TestNodekeywords(object):
def test_no_under(self, testdir): def test_no_under(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def test_pass(): pass def test_pass(): pass

View File

@ -4,7 +4,7 @@ import _pytest._code
from _pytest.config import getcfg, get_common_ancestor, determine_setup from _pytest.config import getcfg, get_common_ancestor, determine_setup
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
class TestParseIni: class TestParseIni(object):
@pytest.mark.parametrize('section, filename', @pytest.mark.parametrize('section, filename',
[('pytest', 'pytest.ini'), ('tool:pytest', 'setup.cfg')]) [('pytest', 'pytest.ini'), ('tool:pytest', 'setup.cfg')])
@ -84,7 +84,7 @@ class TestParseIni:
result = testdir.inline_run("--confcutdir=.") result = testdir.inline_run("--confcutdir=.")
assert result.ret == 0 assert result.ret == 0
class TestConfigCmdlineParsing: class TestConfigCmdlineParsing(object):
def test_parsing_again_fails(self, testdir): def test_parsing_again_fails(self, testdir):
config = testdir.parseconfig() config = testdir.parseconfig()
pytest.raises(AssertionError, lambda: config.parse([])) pytest.raises(AssertionError, lambda: config.parse([]))
@ -115,7 +115,7 @@ class TestConfigCmdlineParsing:
ret = pytest.main("-c " + temp_cfg_file) ret = pytest.main("-c " + temp_cfg_file)
assert ret == _pytest.main.EXIT_OK assert ret == _pytest.main.EXIT_OK
class TestConfigAPI: class TestConfigAPI(object):
def test_config_trace(self, testdir): def test_config_trace(self, testdir):
config = testdir.parseconfig() config = testdir.parseconfig()
l = [] l = []
@ -304,7 +304,7 @@ class TestConfigAPI:
assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir')) assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir'))
class TestConfigFromdictargs: class TestConfigFromdictargs(object):
def test_basic_behavior(self): def test_basic_behavior(self):
from _pytest.config import Config from _pytest.config import Config
option_dict = { option_dict = {
@ -389,19 +389,19 @@ def test_preparse_ordering_with_setuptools(testdir, monkeypatch):
def my_iter(name): def my_iter(name):
assert name == "pytest11" assert name == "pytest11"
class Dist: class Dist(object):
project_name = 'spam' project_name = 'spam'
version = '1.0' version = '1.0'
def _get_metadata(self, name): def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123'] return ['foo.txt,sha256=abc,123']
class EntryPoint: class EntryPoint(object):
name = "mytestplugin" name = "mytestplugin"
dist = Dist() dist = Dist()
def load(self): def load(self):
class PseudoPlugin: class PseudoPlugin(object):
x = 42 x = 42
return PseudoPlugin() return PseudoPlugin()
@ -423,14 +423,14 @@ def test_setuptools_importerror_issue1479(testdir, monkeypatch):
def my_iter(name): def my_iter(name):
assert name == "pytest11" assert name == "pytest11"
class Dist: class Dist(object):
project_name = 'spam' project_name = 'spam'
version = '1.0' version = '1.0'
def _get_metadata(self, name): def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123'] return ['foo.txt,sha256=abc,123']
class EntryPoint: class EntryPoint(object):
name = "mytestplugin" name = "mytestplugin"
dist = Dist() dist = Dist()
@ -450,14 +450,14 @@ def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch):
def my_iter(name): def my_iter(name):
assert name == "pytest11" assert name == "pytest11"
class Dist: class Dist(object):
project_name = 'spam' project_name = 'spam'
version = '1.0' version = '1.0'
def _get_metadata(self, name): def _get_metadata(self, name):
return ['foo.txt,sha256=abc,123'] return ['foo.txt,sha256=abc,123']
class EntryPoint: class EntryPoint(object):
name = "mytestplugin" name = "mytestplugin"
dist = Dist() dist = Dist()
@ -557,7 +557,7 @@ def test_notify_exception(testdir, capfd):
out, err = capfd.readouterr() out, err = capfd.readouterr()
assert "ValueError" in err assert "ValueError" in err
class A: class A(object):
def pytest_internalerror(self, excrepr): def pytest_internalerror(self, excrepr):
return True return True
@ -571,7 +571,7 @@ def test_load_initial_conftest_last_ordering(testdir):
from _pytest.config import get_config from _pytest.config import get_config
pm = get_config().pluginmanager pm = get_config().pluginmanager
class My: class My(object):
def pytest_load_initial_conftests(self): def pytest_load_initial_conftests(self):
pass pass
@ -602,7 +602,7 @@ def test_get_plugin_specs_as_list():
assert _get_plugin_specs_as_list(('foo', 'bar')) == ['foo', 'bar'] assert _get_plugin_specs_as_list(('foo', 'bar')) == ['foo', 'bar']
class TestWarning: class TestWarning(object):
def test_warn_config(self, testdir): def test_warn_config(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
l = [] l = []
@ -641,7 +641,7 @@ class TestWarning:
*WT1*test_warn_on_test_item*:7 hello* *WT1*test_warn_on_test_item*:7 hello*
""") """)
class TestRootdir: class TestRootdir(object):
def test_simple_noini(self, tmpdir): def test_simple_noini(self, tmpdir):
assert get_common_ancestor([tmpdir]) == tmpdir assert get_common_ancestor([tmpdir]) == tmpdir
a = tmpdir.mkdir("a") a = tmpdir.mkdir("a")
@ -699,7 +699,7 @@ class TestRootdir:
assert rootdir == tmpdir assert rootdir == tmpdir
class TestOverrideIniArgs: class TestOverrideIniArgs(object):
@pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split()) @pytest.mark.parametrize("name", "setup.cfg tox.ini pytest.ini".split())
def test_override_ini_names(self, testdir, name): def test_override_ini_names(self, testdir, name):
testdir.tmpdir.join(name).write(py.std.textwrap.dedent(""" testdir.tmpdir.join(name).write(py.std.textwrap.dedent("""

View File

@ -24,14 +24,14 @@ def ConftestWithSetinitial(path):
return conftest return conftest
def conftest_setinitial(conftest, args, confcutdir=None): def conftest_setinitial(conftest, args, confcutdir=None):
class Namespace: class Namespace(object):
def __init__(self): def __init__(self):
self.file_or_dir = args self.file_or_dir = args
self.confcutdir = str(confcutdir) self.confcutdir = str(confcutdir)
self.noconftest = False self.noconftest = False
conftest._set_initial_conftests(Namespace()) conftest._set_initial_conftests(Namespace())
class TestConftestValueAccessGlobal: class TestConftestValueAccessGlobal(object):
def test_basic_init(self, basedir): def test_basic_init(self, basedir):
conftest = PytestPluginManager() conftest = PytestPluginManager()
p = basedir.join("adir") p = basedir.join("adir")
@ -265,7 +265,7 @@ def test_conftest_found_with_double_dash(testdir):
""") """)
class TestConftestVisibility: class TestConftestVisibility(object):
def _setup_tree(self, testdir): # for issue616 def _setup_tree(self, testdir): # for issue616
# example mostly taken from: # example mostly taken from:
# https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html # https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html
@ -398,7 +398,7 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error):
def test_issue1073_conftest_special_objects(testdir): def test_issue1073_conftest_special_objects(testdir):
testdir.makeconftest(""" testdir.makeconftest("""
class DontTouchMe: class DontTouchMe(object):
def __getattr__(self, x): def __getattr__(self, x):
raise Exception('cant touch me') raise Exception('cant touch me')

View File

@ -6,7 +6,7 @@ from _pytest.doctest import DoctestItem, DoctestModule, DoctestTextfile
import pytest import pytest
class TestDoctests: class TestDoctests(object):
def test_collect_testtextfile(self, testdir): def test_collect_testtextfile(self, testdir):
w = testdir.maketxtfile(whatever="") w = testdir.maketxtfile(whatever="")
@ -378,7 +378,7 @@ class TestDoctests:
def test_doctestmodule_two_tests_one_fail(self, testdir): def test_doctestmodule_two_tests_one_fail(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class MyClass: class MyClass(object):
def bad_meth(self): def bad_meth(self):
''' '''
>>> magic = 42 >>> magic = 42
@ -401,7 +401,7 @@ class TestDoctests:
doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE
""") """)
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class MyClass: class MyClass(object):
''' '''
>>> a = "foo " >>> a = "foo "
>>> print(a) >>> print(a)
@ -418,7 +418,7 @@ class TestDoctests:
doctest_optionflags = ELLIPSIS doctest_optionflags = ELLIPSIS
""") """)
p = testdir.makepyfile(""" p = testdir.makepyfile("""
class MyClass: class MyClass(object):
''' '''
>>> a = "foo " >>> a = "foo "
>>> print(a) >>> print(a)
@ -505,7 +505,7 @@ class TestDoctests:
reprec.assertoutcome(failed=1) reprec.assertoutcome(failed=1)
class TestLiterals: class TestLiterals(object):
@pytest.mark.parametrize('config_mode', ['ini', 'comment']) @pytest.mark.parametrize('config_mode', ['ini', 'comment'])
def test_allow_unicode(self, testdir, config_mode): def test_allow_unicode(self, testdir, config_mode):
@ -592,7 +592,7 @@ class TestLiterals:
reprec.assertoutcome(passed=passed, failed=int(not passed)) reprec.assertoutcome(passed=passed, failed=int(not passed))
class TestDoctestSkips: class TestDoctestSkips(object):
""" """
If all examples in a doctest are skipped due to the SKIP option, then If all examples in a doctest are skipped due to the SKIP option, then
the tests should be SKIPPED rather than PASSED. (#957) the tests should be SKIPPED rather than PASSED. (#957)
@ -646,7 +646,7 @@ class TestDoctestSkips:
reprec.assertoutcome(passed=0, skipped=0) reprec.assertoutcome(passed=0, skipped=0)
class TestDoctestAutoUseFixtures: class TestDoctestAutoUseFixtures(object):
SCOPES = ['module', 'session', 'class', 'function'] SCOPES = ['module', 'session', 'class', 'function']
@ -765,7 +765,7 @@ class TestDoctestAutoUseFixtures:
result.stdout.fnmatch_lines(['*=== 1 passed in *']) result.stdout.fnmatch_lines(['*=== 1 passed in *'])
class TestDoctestNamespaceFixture: class TestDoctestNamespaceFixture(object):
SCOPES = ['module', 'session', 'class', 'function'] SCOPES = ['module', 'session', 'class', 'function']
@ -815,7 +815,7 @@ class TestDoctestNamespaceFixture:
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
class TestDoctestReportingOption: class TestDoctestReportingOption(object):
def _run_doctest_report(self, testdir, format): def _run_doctest_report(self, testdir, format):
testdir.makepyfile(""" testdir.makepyfile("""
def foo(): def foo():

View File

@ -79,7 +79,7 @@ class DomNode(object):
return type(self)(self.__node.nextSibling) return type(self)(self.__node.nextSibling)
class TestPython: class TestPython(object):
def test_summing_simple(self, testdir): def test_summing_simple(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -263,7 +263,7 @@ class TestPython:
def test_classname_instance(self, testdir): def test_classname_instance(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
assert 0 assert 0
""") """)
@ -376,7 +376,7 @@ class TestPython:
testdir.makepyfile(""" testdir.makepyfile("""
def test_func(): def test_func():
assert 0 assert 0
class TestHello: class TestHello(object):
def test_hello(self): def test_hello(self):
pass pass
""") """)
@ -569,7 +569,7 @@ def test_mangle_test_address():
def test_dont_configure_on_slaves(tmpdir): def test_dont_configure_on_slaves(tmpdir):
gotten = [] gotten = []
class FakeConfig: class FakeConfig(object):
def __init__(self): def __init__(self):
self.pluginmanager = self self.pluginmanager = self
self.option = self self.option = self
@ -588,7 +588,7 @@ def test_dont_configure_on_slaves(tmpdir):
assert len(gotten) == 1 assert len(gotten) == 1
class TestNonPython: class TestNonPython(object):
def test_summing_simple(self, testdir): def test_summing_simple(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""
import pytest import pytest
@ -750,7 +750,7 @@ def test_double_colon_split_function_issue469(testdir):
def test_double_colon_split_method_issue469(testdir): def test_double_colon_split_method_issue469(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
@pytest.mark.parametrize('param', ["double::colon"]) @pytest.mark.parametrize('param', ["double::colon"])
def test_func(self, param): def test_func(self, param):
pass pass

View File

@ -3,7 +3,7 @@ import os
import py, pytest import py, pytest
from _pytest.mark import MarkGenerator as Mark from _pytest.mark import MarkGenerator as Mark
class TestMark: class TestMark(object):
def test_markinfo_repr(self): def test_markinfo_repr(self):
from _pytest.mark import MarkInfo, Mark from _pytest.mark import MarkInfo, Mark
m = MarkInfo(Mark("hello", (1,2), {})) m = MarkInfo(Mark("hello", (1,2), {}))
@ -301,7 +301,7 @@ def test_parametrized_collected_from_command_line(testdir):
rec.assertoutcome(passed=3) rec.assertoutcome(passed=3)
class TestFunctional: class TestFunctional(object):
def test_mark_per_function(self, testdir): def test_mark_per_function(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
@ -326,7 +326,7 @@ class TestFunctional:
def test_marklist_per_class(self, testdir): def test_marklist_per_class(self, testdir):
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
class TestClass: class TestClass(object):
pytestmark = [pytest.mark.hello, pytest.mark.world] pytestmark = [pytest.mark.hello, pytest.mark.world]
def test_func(self): def test_func(self):
assert TestClass.test_func.hello assert TestClass.test_func.hello
@ -339,7 +339,7 @@ class TestFunctional:
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
pytestmark = [pytest.mark.hello, pytest.mark.world] pytestmark = [pytest.mark.hello, pytest.mark.world]
class TestClass: class TestClass(object):
def test_func(self): def test_func(self):
assert TestClass.test_func.hello assert TestClass.test_func.hello
assert TestClass.test_func.world assert TestClass.test_func.world
@ -352,7 +352,7 @@ class TestFunctional:
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
@pytest.mark.hello @pytest.mark.hello
class TestClass: class TestClass(object):
def test_func(self): def test_func(self):
assert TestClass.test_func.hello assert TestClass.test_func.hello
""") """)
@ -363,7 +363,7 @@ class TestFunctional:
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
@pytest.mark.hello @pytest.mark.hello
class TestClass: class TestClass(object):
pytestmark = pytest.mark.world pytestmark = pytest.mark.world
def test_func(self): def test_func(self):
assert TestClass.test_func.hello assert TestClass.test_func.hello
@ -377,7 +377,7 @@ class TestFunctional:
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
pytestmark = pytest.mark.hello("pos1", x=1, y=2) pytestmark = pytest.mark.hello("pos1", x=1, y=2)
class TestClass: class TestClass(object):
# classlevel overrides module level # classlevel overrides module level
pytestmark = pytest.mark.hello(x=3) pytestmark = pytest.mark.hello(x=3)
@pytest.mark.hello("pos0", z=4) @pytest.mark.hello("pos0", z=4)
@ -403,11 +403,11 @@ class TestFunctional:
# issue 199 - propagate markers into nested classes # issue 199 - propagate markers into nested classes
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
class TestA: class TestA(object):
pytestmark = pytest.mark.a pytestmark = pytest.mark.a
def test_b(self): def test_b(self):
assert True assert True
class TestC: class TestC(object):
# this one didnt get marked # this one didnt get marked
def test_d(self): def test_d(self):
assert True assert True
@ -422,7 +422,7 @@ class TestFunctional:
import pytest import pytest
@pytest.mark.a @pytest.mark.a
class Base: pass class Base(object): pass
@pytest.mark.b @pytest.mark.b
class Test1(Base): class Test1(Base):
@ -441,7 +441,7 @@ class TestFunctional:
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
class TestBase: class TestBase(object):
def test_foo(self): def test_foo(self):
pass pass
@ -465,7 +465,7 @@ class TestFunctional:
import pytest import pytest
@pytest.mark.a @pytest.mark.a
class Base: pass class Base(object): pass
@pytest.mark.b @pytest.mark.b
class Base2(Base): pass class Base2(Base): pass
@ -485,7 +485,7 @@ class TestFunctional:
def test_mark_with_wrong_marker(self, testdir): def test_mark_with_wrong_marker(self, testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
import pytest import pytest
class pytestmark: class pytestmark(object):
pass pass
def test_func(): def test_func():
pass pass
@ -630,7 +630,7 @@ class TestFunctional:
reprec.assertoutcome(skipped=1) reprec.assertoutcome(skipped=1)
class TestKeywordSelection: class TestKeywordSelection(object):
def test_select_simple(self, testdir): def test_select_simple(self, testdir):
file_test = testdir.makepyfile(""" file_test = testdir.makepyfile("""
@ -659,7 +659,7 @@ class TestKeywordSelection:
p = testdir.makepyfile(test_select=""" p = testdir.makepyfile(test_select="""
def test_1(): def test_1():
pass pass
class TestClass: class TestClass(object):
def test_2(self): def test_2(self):
pass pass
""") """)

View File

@ -16,7 +16,7 @@ def mp():
def test_setattr(): def test_setattr():
class A: class A(object):
x = 1 x = 1
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -39,7 +39,7 @@ def test_setattr():
assert A.x == 5 assert A.x == 5
class TestSetattrWithImportPath: class TestSetattrWithImportPath(object):
def test_string_expression(self, monkeypatch): def test_string_expression(self, monkeypatch):
monkeypatch.setattr("os.path.abspath", lambda x: "hello2") monkeypatch.setattr("os.path.abspath", lambda x: "hello2")
assert os.path.abspath("123") == "hello2" assert os.path.abspath("123") == "hello2"
@ -79,7 +79,7 @@ class TestSetattrWithImportPath:
def test_delattr(): def test_delattr():
class A: class A(object):
x = 1 x = 1
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -294,7 +294,7 @@ class SampleNewInherit(SampleNew):
pass pass
class SampleOld: class SampleOld(object):
# oldstyle on python2 # oldstyle on python2
@staticmethod @staticmethod
def hello(): def hello():

View File

@ -26,7 +26,7 @@ def test_setup_func_with_setup_decorator():
from _pytest.nose import call_optional from _pytest.nose import call_optional
l = [] l = []
class A: class A(object):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def f(self): def f(self):
l.append(1) l.append(1)
@ -38,7 +38,7 @@ def test_setup_func_with_setup_decorator():
def test_setup_func_not_callable(): def test_setup_func_not_callable():
from _pytest.nose import call_optional from _pytest.nose import call_optional
class A: class A(object):
f = 1 f = 1
call_optional(A(), "f") call_optional(A(), "f")
@ -270,7 +270,7 @@ def test_nose_setup_ordering(testdir):
def setup_module(mod): def setup_module(mod):
mod.visited = True mod.visited = True
class TestClass: class TestClass(object):
def setup(self): def setup(self):
assert visited assert visited
def test_first(self): def test_first(self):
@ -377,7 +377,7 @@ def test_istest_class_decorator(testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import nose.tools import nose.tools
@nose.tools.istest @nose.tools.istest
class NotTestPrefix: class NotTestPrefix(object):
def test_method(self): def test_method(self):
pass pass
""") """)
@ -388,7 +388,7 @@ def test_nottest_class_decorator(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import nose.tools import nose.tools
@nose.tools.nottest @nose.tools.nottest
class TestPrefix: class TestPrefix(object):
def test_method(self): def test_method(self):
pass pass
""") """)

View File

@ -8,7 +8,7 @@ from _pytest import config as parseopt
def parser(): def parser():
return parseopt.Parser() return parseopt.Parser()
class TestParser: class TestParser(object):
def test_no_help_by_default(self, capsys): def test_no_help_by_default(self, capsys):
parser = parseopt.Parser(usage="xyz") parser = parseopt.Parser(usage="xyz")
pytest.raises(SystemExit, lambda: parser.parse(["-h"])) pytest.raises(SystemExit, lambda: parser.parse(["-h"]))
@ -139,7 +139,7 @@ class TestParser:
parser.addoption("--hello", dest="hello", action="store") parser.addoption("--hello", dest="hello", action="store")
parser.addoption("--world", dest="world", default=42) parser.addoption("--world", dest="world", default=42)
class A: class A(object):
pass pass
option = A() option = A()

View File

@ -2,7 +2,7 @@
import sys import sys
import pytest import pytest
class TestPasteCapture: class TestPasteCapture(object):
@pytest.fixture @pytest.fixture
def pastebinlist(self, monkeypatch, request): def pastebinlist(self, monkeypatch, request):
@ -71,7 +71,7 @@ class TestPasteCapture:
]) ])
class TestPaste: class TestPaste(object):
@pytest.fixture @pytest.fixture
def pastebin(self, request): def pastebin(self, request):
@ -88,7 +88,7 @@ class TestPaste:
def mocked(url, data): def mocked(url, data):
calls.append((url, data)) calls.append((url, data))
class DummyFile: class DummyFile(object):
def read(self): def read(self):
# part of html of a normal response # part of html of a normal response
return b'View <a href="/raw/3c0c6750bd">raw</a>.' return b'View <a href="/raw/3c0c6750bd">raw</a>.'

View File

@ -18,7 +18,7 @@ def custom_pdb_calls():
called = [] called = []
# install dummy debugger class and track which methods were called on it # install dummy debugger class and track which methods were called on it
class _CustomPdb: class _CustomPdb(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
called.append("init") called.append("init")
@ -33,7 +33,7 @@ def custom_pdb_calls():
class TestPDB: class TestPDB(object):
@pytest.fixture @pytest.fixture
def pdblist(self, request): def pdblist(self, request):
@ -374,7 +374,7 @@ class TestPDB:
def test_pdb_custom_cls_with_settrace(self, testdir, monkeypatch): def test_pdb_custom_cls_with_settrace(self, testdir, monkeypatch):
testdir.makepyfile(custom_pdb=""" testdir.makepyfile(custom_pdb="""
class CustomPdb: class CustomPdb(object):
def set_trace(*args, **kwargs): def set_trace(*args, **kwargs):
print 'custom set_trace>' print 'custom set_trace>'
""") """)

View File

@ -11,7 +11,7 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED, Session
def pytestpm(): def pytestpm():
return PytestPluginManager() return PytestPluginManager()
class TestPytestPluginInteractions: class TestPytestPluginInteractions(object):
def test_addhooks_conftestplugin(self, testdir): def test_addhooks_conftestplugin(self, testdir):
testdir.makepyfile(newhooks=""" testdir.makepyfile(newhooks="""
def pytest_myhook(xyz): def pytest_myhook(xyz):
@ -85,7 +85,7 @@ class TestPytestPluginInteractions:
config = testdir.parseconfig() config = testdir.parseconfig()
l = [] l = []
class A: class A(object):
def pytest_configure(self, config): def pytest_configure(self, config):
l.append(self) l.append(self)
@ -105,11 +105,11 @@ class TestPytestPluginInteractions:
pytestpm = get_config().pluginmanager # fully initialized with plugins pytestpm = get_config().pluginmanager # fully initialized with plugins
saveindent = [] saveindent = []
class api1: class api1(object):
def pytest_plugin_registered(self): def pytest_plugin_registered(self):
saveindent.append(pytestpm.trace.root.indent) saveindent.append(pytestpm.trace.root.indent)
class api2: class api2(object):
def pytest_plugin_registered(self): def pytest_plugin_registered(self):
saveindent.append(pytestpm.trace.root.indent) saveindent.append(pytestpm.trace.root.indent)
raise ValueError() raise ValueError()
@ -156,11 +156,11 @@ class TestPytestPluginInteractions:
def test_warn_on_deprecated_multicall(self, pytestpm): def test_warn_on_deprecated_multicall(self, pytestpm):
warnings = [] warnings = []
class get_warnings: class get_warnings(object):
def pytest_logwarning(self, message): def pytest_logwarning(self, message):
warnings.append(message) warnings.append(message)
class Plugin: class Plugin(object):
def pytest_configure(self, __multicall__): def pytest_configure(self, __multicall__):
pass pass
@ -173,11 +173,11 @@ class TestPytestPluginInteractions:
def test_warn_on_deprecated_addhooks(self, pytestpm): def test_warn_on_deprecated_addhooks(self, pytestpm):
warnings = [] warnings = []
class get_warnings: class get_warnings(object):
def pytest_logwarning(self, code, fslocation, message, nodeid): def pytest_logwarning(self, code, fslocation, message, nodeid):
warnings.append(message) warnings.append(message)
class Plugin: class Plugin(object):
def pytest_testhook(): def pytest_testhook():
pass pass
@ -221,7 +221,7 @@ def test_importplugin_error_message(testdir, pytestpm):
assert py.std.re.match(expected, str(excinfo.value)) assert py.std.re.match(expected, str(excinfo.value))
class TestPytestPluginManager: class TestPytestPluginManager(object):
def test_register_imported_modules(self): def test_register_imported_modules(self):
pm = PytestPluginManager() pm = PytestPluginManager()
mod = py.std.types.ModuleType("x.y.pytest_hello") mod = py.std.types.ModuleType("x.y.pytest_hello")
@ -348,7 +348,7 @@ class TestPytestPluginManager:
pytestpm.consider_conftest(mod) pytestpm.consider_conftest(mod)
class TestPytestPluginManagerBootstrapming: class TestPytestPluginManagerBootstrapming(object):
def test_preparse_args(self, pytestpm): def test_preparse_args(self, pytestpm):
pytest.raises(ImportError, lambda: pytest.raises(ImportError, lambda:
pytestpm.consider_preparse(["xyz", "-p", "hello123"])) pytestpm.consider_preparse(["xyz", "-p", "hello123"]))

View File

@ -12,7 +12,7 @@ def test_make_hook_recorder(testdir):
pytest.xfail("internal reportrecorder tests need refactoring") pytest.xfail("internal reportrecorder tests need refactoring")
class rep: class rep(object):
excinfo = None excinfo = None
passed = False passed = False
failed = True failed = True
@ -25,7 +25,7 @@ def test_make_hook_recorder(testdir):
failures = recorder.getfailures() failures = recorder.getfailures()
assert failures == [rep] assert failures == [rep]
class rep: class rep(object):
excinfo = None excinfo = None
passed = False passed = False
failed = False failed = False
@ -74,7 +74,7 @@ def test_testdir_runs_with_plugin(testdir):
def make_holder(): def make_holder():
class apiclass: class apiclass(object):
def pytest_xyz(self, arg): def pytest_xyz(self, arg):
"x" "x"
def pytest_xyz_noarg(self): def pytest_xyz_noarg(self):

View File

@ -70,7 +70,7 @@ def test_write_log_entry():
assert entry_lines[1:] == [' '+line for line in longrepr.splitlines()] assert entry_lines[1:] == [' '+line for line in longrepr.splitlines()]
class TestWithFunctionIntegration: class TestWithFunctionIntegration(object):
# XXX (hpk) i think that the resultlog plugin should # XXX (hpk) i think that the resultlog plugin should
# provide a Parser object so that one can remain # provide a Parser object so that one can remain
# ignorant regarding formatting details. # ignorant regarding formatting details.

View File

@ -8,7 +8,7 @@ import pytest
import sys import sys
from _pytest import runner, main from _pytest import runner, main
class TestSetupState: class TestSetupState(object):
def test_setup(self, testdir): def test_setup(self, testdir):
ss = runner.SetupState() ss = runner.SetupState()
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
@ -71,7 +71,7 @@ class TestSetupState:
assert err.value.args == ('oops2',) assert err.value.args == ('oops2',)
class BaseFunctionalTests: class BaseFunctionalTests(object):
def test_passfunction(self, testdir): def test_passfunction(self, testdir):
reports = testdir.runitem(""" reports = testdir.runitem("""
def test_func(): def test_func():
@ -200,7 +200,7 @@ class BaseFunctionalTests:
rec = testdir.inline_runsource(""" rec = testdir.inline_runsource("""
import pytest import pytest
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
def teardown_class(cls): def teardown_class(cls):
@ -239,7 +239,7 @@ class BaseFunctionalTests:
rec = testdir.inline_runsource(""" rec = testdir.inline_runsource("""
import pytest import pytest
class TestClass: class TestClass(object):
def teardown_method(self, x, y, z): def teardown_method(self, x, y, z):
pass pass
@ -351,12 +351,12 @@ class TestExecutionForked(BaseFunctionalTests):
assert rep.failed assert rep.failed
assert rep.when == "???" assert rep.when == "???"
class TestSessionReports: class TestSessionReports(object):
def test_collect_result(self, testdir): def test_collect_result(self, testdir):
col = testdir.getmodulecol(""" col = testdir.getmodulecol("""
def test_func1(): def test_func1():
pass pass
class TestClass: class TestClass(object):
pass pass
""") """)
rep = runner.collect_one_node(col) rep = runner.collect_one_node(col)
@ -409,7 +409,7 @@ def test_runtest_in_module_ordering(testdir):
import pytest import pytest
def pytest_runtest_setup(item): # runs after class-level! def pytest_runtest_setup(item): # runs after class-level!
item.function.mylist.append("module") item.function.mylist.append("module")
class TestClass: class TestClass(object):
def pytest_runtest_setup(self, item): def pytest_runtest_setup(self, item):
assert not hasattr(item.function, 'mylist') assert not hasattr(item.function, 'mylist')
item.function.mylist = ['class'] item.function.mylist = ['class']
@ -680,7 +680,7 @@ def test_store_except_info_on_eror():
sys.last_traceback and friends. sys.last_traceback and friends.
""" """
# Simulate item that raises a specific exception # Simulate item that raises a specific exception
class ItemThatRaises: class ItemThatRaises(object):
def runtest(self): def runtest(self):
raise IndexError('TEST') raise IndexError('TEST')
try: try:
@ -693,7 +693,7 @@ def test_store_except_info_on_eror():
assert sys.last_traceback assert sys.last_traceback
class TestReportContents: class TestReportContents(object):
""" """
Test user-level API of ``TestReport`` objects. Test user-level API of ``TestReport`` objects.
""" """

View File

@ -24,7 +24,7 @@ def test_module_and_function_setup(testdir):
assert modlevel[0] == 42 assert modlevel[0] == 42
assert test_modlevel.answer == 17 assert test_modlevel.answer == 17
class TestFromClass: class TestFromClass(object):
def test_module(self): def test_module(self):
assert modlevel[0] == 42 assert modlevel[0] == 42
assert not hasattr(test_modlevel, 'answer') assert not hasattr(test_modlevel, 'answer')
@ -69,7 +69,7 @@ def test_setup_function_failure_no_teardown(testdir):
def test_class_setup(testdir): def test_class_setup(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestSimpleClassSetup: class TestSimpleClassSetup(object):
clslevel = [] clslevel = []
def setup_class(cls): def setup_class(cls):
cls.clslevel.append(23) cls.clslevel.append(23)
@ -92,7 +92,7 @@ def test_class_setup(testdir):
def test_class_setup_failure_no_teardown(testdir): def test_class_setup_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestSimpleClassSetup: class TestSimpleClassSetup(object):
clslevel = [] clslevel = []
def setup_class(cls): def setup_class(cls):
0/0 0/0
@ -110,7 +110,7 @@ def test_class_setup_failure_no_teardown(testdir):
def test_method_setup(testdir): def test_method_setup(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestSetupMethod: class TestSetupMethod(object):
def setup_method(self, meth): def setup_method(self, meth):
self.methsetup = meth self.methsetup = meth
def teardown_method(self, meth): def teardown_method(self, meth):
@ -126,7 +126,7 @@ def test_method_setup(testdir):
def test_method_setup_failure_no_teardown(testdir): def test_method_setup_failure_no_teardown(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestMethodSetup: class TestMethodSetup(object):
clslevel = [] clslevel = []
def setup_method(self, method): def setup_method(self, method):
self.clslevel.append(1) self.clslevel.append(1)
@ -145,7 +145,7 @@ def test_method_setup_failure_no_teardown(testdir):
def test_method_generator_setup(testdir): def test_method_generator_setup(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestSetupTeardownOnInstance: class TestSetupTeardownOnInstance(object):
def setup_class(cls): def setup_class(cls):
cls.classsetup = True cls.classsetup = True
@ -195,7 +195,7 @@ def test_func_generator_setup(testdir):
def test_method_setup_uses_fresh_instances(testdir): def test_method_setup_uses_fresh_instances(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
class TestSelfState1: class TestSelfState1(object):
memory = [] memory = []
def test_hello(self): def test_hello(self):
self.memory.append(self) self.memory.append(self)
@ -276,7 +276,7 @@ def test_setup_teardown_function_level_with_optional_argument(testdir, monkeypat
def test_function_1(): pass def test_function_1(): pass
def test_function_2(): pass def test_function_2(): pass
class Test: class Test(object):
def setup_method(self, {arg}): trace('setup_method') def setup_method(self, {arg}): trace('setup_method')
def teardown_method(self, {arg}): trace('teardown_method') def teardown_method(self, {arg}): trace('teardown_method')

View File

@ -2,7 +2,7 @@ import pytest
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
class SessionTests: class SessionTests(object):
def test_basic_testitem_events(self, testdir): def test_basic_testitem_events(self, testdir):
tfile = testdir.makepyfile(""" tfile = testdir.makepyfile("""
def test_one(): def test_one():
@ -11,7 +11,7 @@ class SessionTests:
assert 0 assert 0
def test_other(): def test_other():
raise ValueError(23) raise ValueError(23)
class TestClass: class TestClass(object):
def test_two(self, someargs): def test_two(self, someargs):
pass pass
""") """)
@ -97,12 +97,12 @@ class SessionTests:
def test_broken_repr(self, testdir): def test_broken_repr(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
class BrokenRepr1: class BrokenRepr1(object):
foo=0 foo=0
def __repr__(self): def __repr__(self):
raise Exception("Ha Ha fooled you, I'm a broken repr().") raise Exception("Ha Ha fooled you, I'm a broken repr().")
class TestBrokenClass: class TestBrokenClass(object):
def test_explicit_bad_repr(self): def test_explicit_bad_repr(self):
t = BrokenRepr1() t = BrokenRepr1()
pytest.raises(Exception, 'repr(t)') pytest.raises(Exception, 'repr(t)')
@ -145,7 +145,7 @@ class TestNewSession(SessionTests):
l.append(2) l.append(2)
def test_3(): def test_3():
assert l == [1,2] assert l == [1,2]
class Testmygroup: class Testmygroup(object):
reslist = l reslist = l
def test_1(self): def test_1(self):
self.reslist.append(1) self.reslist.append(1)
@ -167,7 +167,7 @@ class TestNewSession(SessionTests):
def test_one(): def test_one():
raise ValueError() raise ValueError()
class TestX: class TestX(object):
def test_method_one(self): def test_method_one(self):
pass pass

View File

@ -5,7 +5,7 @@ from _pytest.skipping import MarkEvaluator, folded_skips, pytest_runtest_setup
from _pytest.runner import runtestprotocol from _pytest.runner import runtestprotocol
class TestEvaluator: class TestEvaluator(object):
def test_no_marker(self, testdir): def test_no_marker(self, testdir):
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
evalskipif = MarkEvaluator(item, 'skipif') evalskipif = MarkEvaluator(item, 'skipif')
@ -114,7 +114,7 @@ class TestEvaluator:
def test_skipif_class(self, testdir): def test_skipif_class(self, testdir):
item, = testdir.getitems(""" item, = testdir.getitems("""
import pytest import pytest
class TestClass: class TestClass(object):
pytestmark = pytest.mark.skipif("config._hackxyz") pytestmark = pytest.mark.skipif("config._hackxyz")
def test_func(self): def test_func(self):
pass pass
@ -126,7 +126,7 @@ class TestEvaluator:
assert expl == "condition: config._hackxyz" assert expl == "condition: config._hackxyz"
class TestXFail: class TestXFail(object):
@pytest.mark.parametrize('strict', [True, False]) @pytest.mark.parametrize('strict', [True, False])
def test_xfail_simple(self, testdir, strict): def test_xfail_simple(self, testdir, strict):
@ -452,7 +452,7 @@ class TestXFail:
assert result.ret == (1 if strict else 0) assert result.ret == (1 if strict else 0)
class TestXFailwithSetupTeardown: class TestXFailwithSetupTeardown(object):
def test_failing_setup_issue9(self, testdir): def test_failing_setup_issue9(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -484,7 +484,7 @@ class TestXFailwithSetupTeardown:
]) ])
class TestSkip: class TestSkip(object):
def test_skip_class(self, testdir): def test_skip_class(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -581,7 +581,7 @@ class TestSkip:
"*1 skipped*", "*1 skipped*",
]) ])
class TestSkipif: class TestSkipif(object):
def test_skipif_conditional(self, testdir): def test_skipif_conditional(self, testdir):
item = testdir.getitem(""" item = testdir.getitem("""
import pytest import pytest
@ -648,7 +648,7 @@ def test_skipif_class(testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import pytest import pytest
class TestClass: class TestClass(object):
pytestmark = pytest.mark.skipif("True") pytestmark = pytest.mark.skipif("True")
def test_that(self): def test_that(self):
assert 0 assert 0
@ -667,7 +667,7 @@ def test_skip_reasons_folding():
message = "justso" message = "justso"
longrepr = (path, lineno, message) longrepr = (path, lineno, message)
class X: class X(object):
pass pass
ev1 = X() ev1 = X()
ev1.when = "execute" ev1.when = "execute"
@ -694,7 +694,7 @@ def test_skipped_reasons_functional(testdir):
doskip() doskip()
def test_func(): def test_func():
pass pass
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
doskip() doskip()
""", """,
@ -892,7 +892,7 @@ def test_imperativeskip_on_xfail_test(testdir):
*2 skipped* *2 skipped*
""") """)
class TestBooleanCondition: class TestBooleanCondition(object):
def test_skipif(self, testdir): def test_skipif(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest

View File

@ -16,7 +16,7 @@ from _pytest.terminal import build_summary_stats_line, _plugin_nameversions
DistInfo = collections.namedtuple('DistInfo', ['project_name', 'version']) DistInfo = collections.namedtuple('DistInfo', ['project_name', 'version'])
class Option: class Option(object):
def __init__(self, verbose=False, fulltrace=False): def __init__(self, verbose=False, fulltrace=False):
self.verbose = verbose self.verbose = verbose
self.fulltrace = fulltrace self.fulltrace = fulltrace
@ -56,7 +56,7 @@ def test_plugin_nameversion(input, expected):
assert result == expected assert result == expected
class TestTerminal: class TestTerminal(object):
def test_pass_skip_fail(self, testdir, option): def test_pass_skip_fail(self, testdir, option):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest
@ -127,7 +127,7 @@ class TestTerminal:
def test_itemreport_subclasses_show_subclassed_file(self, testdir): def test_itemreport_subclasses_show_subclassed_file(self, testdir):
testdir.makepyfile(test_p1=""" testdir.makepyfile(test_p1="""
class BaseTests: class BaseTests(object):
def test_p1(self): def test_p1(self):
pass pass
class TestClass(BaseTests): class TestClass(BaseTests):
@ -151,7 +151,7 @@ class TestTerminal:
def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir): def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir):
a = testdir.mkpydir("a123") a = testdir.mkpydir("a123")
a.join("test_hello123.py").write(_pytest._code.Source(""" a.join("test_hello123.py").write(_pytest._code.Source("""
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""")) """))
@ -204,7 +204,7 @@ class TestTerminal:
result.stdout.fnmatch_lines(['*KeyboardInterrupt*']) result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
class TestCollectonly: class TestCollectonly(object):
def test_collectonly_basic(self, testdir): def test_collectonly_basic(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def test_func(): def test_func():
@ -249,7 +249,7 @@ class TestCollectonly:
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def test_func1(): def test_func1():
pass pass
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""") """)
@ -310,7 +310,7 @@ def test_repr_python_version(monkeypatch):
finally: finally:
monkeypatch.undo() # do this early as pytest can get confused monkeypatch.undo() # do this early as pytest can get confused
class TestFixtureReporting: class TestFixtureReporting(object):
def test_setup_fixture_error(self, testdir): def test_setup_fixture_error(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def setup_function(function): def setup_function(function):
@ -395,7 +395,7 @@ class TestFixtureReporting:
"*1 failed*", "*1 failed*",
]) ])
class TestTerminalFunctional: class TestTerminalFunctional(object):
def test_deselected(self, testdir): def test_deselected(self, testdir):
testpath = testdir.makepyfile(""" testpath = testdir.makepyfile("""
def test_one(): def test_one():
@ -431,7 +431,7 @@ class TestTerminalFunctional:
p1 = testdir.makepyfile(""" p1 = testdir.makepyfile("""
def test_passes(): def test_passes():
pass pass
class TestClass: class TestClass(object):
def test_method(self): def test_method(self):
pass pass
""") """)
@ -487,7 +487,7 @@ class TestTerminalFunctional:
raise ValueError() raise ValueError()
def test_pass(): def test_pass():
pass pass
class TestClass: class TestClass(object):
def test_skip(self): def test_skip(self):
pytest.skip("hello") pytest.skip("hello")
def test_gen(): def test_gen():
@ -612,8 +612,8 @@ def test_color_yes_collection_on_non_atty(testdir, verbose):
def test_getreportopt(): def test_getreportopt():
class config: class config(object):
class option: class option(object):
reportchars = "" reportchars = ""
disablepytestwarnings = True disablepytestwarnings = True
@ -683,7 +683,7 @@ def test_traceconfig(testdir, monkeypatch):
assert result.ret == EXIT_NOTESTSCOLLECTED assert result.ret == EXIT_NOTESTSCOLLECTED
class TestGenericReporting: class TestGenericReporting(object):
""" this test class can be subclassed with a different option """ this test class can be subclassed with a different option
provider to run e.g. distributed tests. provider to run e.g. distributed tests.
""" """

View File

@ -34,7 +34,7 @@ def test_ensuretemp(recwarn):
assert d1 == d2 assert d1 == d2
assert d1.check(dir=1) assert d1.check(dir=1)
class TestTempdirHandler: class TestTempdirHandler(object):
def test_mktemp(self, testdir): def test_mktemp(self, testdir):
from _pytest.tmpdir import TempdirFactory from _pytest.tmpdir import TempdirFactory
config = testdir.parseconfig() config = testdir.parseconfig()
@ -48,7 +48,7 @@ class TestTempdirHandler:
assert tmp2.relto(t.getbasetemp()).startswith("this") assert tmp2.relto(t.getbasetemp()).startswith("this")
assert tmp2 != tmp assert tmp2 != tmp
class TestConfigTmpdir: class TestConfigTmpdir(object):
def test_getbasetemp_custom_removes_old(self, testdir): def test_getbasetemp_custom_removes_old(self, testdir):
mytemp = testdir.tmpdir.join("xyz") mytemp = testdir.tmpdir.join("xyz")
p = testdir.makepyfile(""" p = testdir.makepyfile("""

View File

@ -385,7 +385,7 @@ def test_trial_testfunction_todo_property(testdir):
reprec.assertoutcome(skipped=1) reprec.assertoutcome(skipped=1)
class TestTrialUnittest: class TestTrialUnittest(object):
def setup_class(cls): def setup_class(cls):
cls.ut = pytest.importorskip("twisted.trial.unittest") cls.ut = pytest.importorskip("twisted.trial.unittest")
@ -704,7 +704,7 @@ def test_unittest_setup_interaction(testdir, fix_type, stmt):
def test_non_unittest_no_setupclass_support(testdir): def test_non_unittest_no_setupclass_support(testdir):
testpath = testdir.makepyfile(""" testpath = testdir.makepyfile("""
class TestFoo: class TestFoo(object):
x = 0 x = 0
@classmethod @classmethod