Skip to content

Commit fb0b906

Browse files
committed
New-style classes implemented for python 2.7 - #2147
1 parent da828aa commit fb0b906

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+351
-349
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Michael Aquilina
108108
Michael Birtwell
109109
Michael Droettboom
110110
Michael Seifert
111+
Michal Wajszczuk
111112
Mike Lundy
112113
Ned Batchelder
113114
Neven Mundar

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Changes
2121
-------
2222

2323
* Old-style classes have been changed to new-style classes in order to improve
24-
compatability with Python 2. Thanks to `@mandeep`_ for the PR (`#2147`_).
24+
compatibility with Python 2. Thanks to `@MichalTHEDUDE`_ and `@mandeep`_ for the PR (`#2147`_).
2525

2626
* It is now possible to skip test classes from being collected by setting a
2727
``__test__`` attribute to ``False`` in the class body (`#2007`_). Thanks
@@ -61,6 +61,7 @@ Changes
6161
.. _@wheerd: https://github.com/wheerd
6262
.. _@fogo: https://github.com/fogo
6363
.. _@mandeep: https://github.com/mandeep
64+
.. _@MichalTHEDUDE: https://github.com/MichalTHEDUDE
6465
.. _@unsignedint: https://github.com/unsignedint
6566
.. _@Kriechi: https://github.com/Kriechi
6667

_pytest/vendored_packages/pluggy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def normalize_hookimpl_opts(opts):
167167
opts.setdefault("optionalhook", False)
168168

169169

170-
class _TagTracer:
170+
class _TagTracer(object):
171171
def __init__(self):
172172
self._tag2proc = {}
173173
self.writer = None
@@ -214,7 +214,7 @@ def setprocessor(self, tags, processor):
214214
self._tag2proc[tags] = processor
215215

216216

217-
class _TagTracerSub:
217+
class _TagTracerSub(object):
218218
def __init__(self, root, tags):
219219
self.root = root
220220
self.tags = tags
@@ -254,7 +254,7 @@ def _wrapped_call(wrap_controller, func):
254254
return call_outcome.get_result()
255255

256256

257-
class _CallOutcome:
257+
class _CallOutcome(object):
258258
""" Outcome of a function call, either an exception or a proper result.
259259
Calling the ``get_result`` method will return the result or reraise
260260
the exception raised when the function was called. """
@@ -286,7 +286,7 @@ def _reraise(cls, val, tb):
286286
""")
287287

288288

289-
class _TracedHookExecution:
289+
class _TracedHookExecution(object):
290290
def __init__(self, pluginmanager, before, after):
291291
self.pluginmanager = pluginmanager
292292
self.before = before
@@ -580,7 +580,7 @@ def subset_hook_caller(self, name, remove_plugins):
580580
return orig
581581

582582

583-
class _MultiCall:
583+
class _MultiCall(object):
584584
""" execute a call into multiple python functions/methods. """
585585

586586
# XXX note that the __multicall__ argument is supported only
@@ -673,7 +673,7 @@ def varnames(func, startindex=None):
673673
return x
674674

675675

676-
class _HookRelay:
676+
class _HookRelay(object):
677677
""" hook holder object for performing 1:N hook calls where N is the number
678678
of registered plugins.
679679

doc/en/assert.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ provides an alternative explanation for ``Foo`` objects::
223223
now, given this test module::
224224

225225
# content of test_foocompare.py
226-
class Foo:
226+
class Foo(object):
227227
def __init__(self, val):
228228
self.val = val
229229

doc/en/example/assertion/failure_demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Bar(object):
128128
def globf(x):
129129
return x+1
130130

131-
class TestRaises:
131+
class TestRaises(object):
132132
def test_raises(self):
133133
s = 'qwe'
134134
raises(TypeError, "int(s)")
@@ -167,7 +167,7 @@ def test_dynamic_compile_shows_nicely():
167167

168168

169169

170-
class TestMoreErrors:
170+
class TestMoreErrors(object):
171171
def test_complex_error(self):
172172
def f():
173173
return 44
@@ -213,23 +213,23 @@ def test_try_finally(self):
213213
x = 0
214214

215215

216-
class TestCustomAssertMsg:
216+
class TestCustomAssertMsg(object):
217217

218218
def test_single_line(self):
219-
class A:
219+
class A(object):
220220
a = 1
221221
b = 2
222222
assert A.a == b, "A.a appears not to be b"
223223

224224
def test_multiline(self):
225-
class A:
225+
class A(object):
226226
a = 1
227227
b = 2
228228
assert A.a == b, "A.a appears not to be b\n" \
229229
"or does not appear to be b\none of those"
230230

231231
def test_custom_repr(self):
232-
class JSON:
232+
class JSON(object):
233233
a = 1
234234
def __repr__(self):
235235
return "This is JSON\n{\n 'foo': 'bar'\n}"

doc/en/example/assertion/test_setup_flow_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def setup_module(module):
22
module.TestStateFullThing.classcount = 0
33

4-
class TestStateFullThing:
4+
class TestStateFullThing(object):
55
def setup_class(cls):
66
cls.classcount += 1
77

doc/en/example/attic.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ example: specifying and selecting acceptance tests
1515
def pytest_funcarg__accept(request):
1616
return AcceptFixture(request)
1717

18-
class AcceptFixture:
18+
class AcceptFixture(object):
1919
def __init__(self, request):
2020
if not request.config.option.acceptance:
2121
pytest.skip("specify -A to run acceptance tests")
@@ -61,7 +61,7 @@ extend the `accept example`_ by putting this in our test module:
6161
arg.tmpdir.mkdir("special")
6262
return arg
6363

64-
class TestSpecialAcceptance:
64+
class TestSpecialAcceptance(object):
6565
def test_sometest(self, accept):
6666
assert accept.tmpdir.join("special").check()
6767

doc/en/example/costlysetup/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def setup(request):
77
yield setup
88
setup.finalize()
99

10-
class CostlySetup:
10+
class CostlySetup(object):
1111
def __init__(self):
1212
import time
1313
print ("performing costly setup")

doc/en/example/markers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can "mark" a test function with custom metadata like this::
2121
pass
2222
def test_another():
2323
pass
24-
class TestClass:
24+
class TestClass(object):
2525
def test_method(self):
2626
pass
2727

@@ -242,7 +242,7 @@ its test methods::
242242
# content of test_mark_classlevel.py
243243
import pytest
244244
@pytest.mark.webtest
245-
class TestClass:
245+
class TestClass(object):
246246
def test_startup(self):
247247
pass
248248
def test_startup_and_more(self):
@@ -256,14 +256,14 @@ To remain backward-compatible with Python 2.4 you can also set a
256256

257257
import pytest
258258

259-
class TestClass:
259+
class TestClass(object):
260260
pytestmark = pytest.mark.webtest
261261

262262
or if you need to use multiple markers you can use a list::
263263

264264
import pytest
265265

266-
class TestClass:
266+
class TestClass(object):
267267
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
268268

269269
You can also set a module level marker::
@@ -407,7 +407,7 @@ code you can read over all such settings. Example::
407407
pytestmark = pytest.mark.glob("module", x=1)
408408

409409
@pytest.mark.glob("class", x=2)
410-
class TestClass:
410+
class TestClass(object):
411411
@pytest.mark.glob("function", x=3)
412412
def test_something(self):
413413
pass

doc/en/example/multipython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def python1(request, tmpdir):
1616
def python2(request, python1):
1717
return Python(request.param, python1.picklefile)
1818

19-
class Python:
19+
class Python(object):
2020
def __init__(self, version, picklefile):
2121
self.pythonpath = py.path.local.sysfind(version)
2222
if not self.pythonpath:

doc/en/example/parametrize.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ only have to work a bit to construct the correct arguments for pytest's
168168
scenario1 = ('basic', {'attribute': 'value'})
169169
scenario2 = ('advanced', {'attribute': 'value2'})
170170

171-
class TestSampleWithScenarios:
171+
class TestSampleWithScenarios(object):
172172
scenarios = [scenario1, scenario2]
173173

174174
def test_demo1(self, attribute):
@@ -241,9 +241,9 @@ creates a database object for the actual test invocations::
241241
if 'db' in metafunc.fixturenames:
242242
metafunc.parametrize("db", ['d1', 'd2'], indirect=True)
243243

244-
class DB1:
244+
class DB1(object):
245245
"one database object"
246-
class DB2:
246+
class DB2(object):
247247
"alternative database object"
248248

249249
@pytest.fixture
@@ -350,7 +350,7 @@ parametrizer`_ but in a lot less code::
350350
metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
351351
for funcargs in funcarglist])
352352

353-
class TestClass:
353+
class TestClass(object):
354354
# a map specifying multiple argument sets for a test method
355355
params = {
356356
'test_equals': [dict(a=1, b=2), dict(a=3, b=3), ],

doc/en/example/pythoncollection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def test_function():
55
pass
66

7-
class TestClass:
7+
class TestClass(object):
88
def test_method(self):
99
pass
1010
def test_anothermethod(self):

doc/en/example/pythoncollection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ This would make ``pytest`` look for tests in files that match the ``check_*
107107
that match ``*_check``. For example, if we have::
108108

109109
# content of check_myapp.py
110-
class CheckMyApp:
110+
class CheckMyApp(object):
111111
def simple_check(self):
112112
pass
113113
def complex_check(self):

doc/en/example/reportingdemo.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ get on the terminal - we are working on that)::
550550
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
551551
552552
def test_single_line(self):
553-
class A:
553+
class A(object):
554554
a = 1
555555
b = 2
556556
> assert A.a == b, "A.a appears not to be b"
@@ -564,7 +564,7 @@ get on the terminal - we are working on that)::
564564
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
565565
566566
def test_multiline(self):
567-
class A:
567+
class A(object):
568568
a = 1
569569
b = 2
570570
> 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)::
581581
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
582582
583583
def test_custom_repr(self):
584-
class JSON:
584+
class JSON(object):
585585
a = 1
586586
def __repr__(self):
587587
return "This is JSON\n{\n 'foo': 'bar'\n}"

doc/en/example/simple.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ tests in a class. Here is a test module example:
425425
import pytest
426426
427427
@pytest.mark.incremental
428-
class TestUserHandling:
428+
class TestUserHandling(object):
429429
def test_login(self):
430430
pass
431431
def test_modification(self):
@@ -483,7 +483,7 @@ Here is an example for making a ``db`` fixture available in a directory:
483483
# content of a/conftest.py
484484
import pytest
485485
486-
class DB:
486+
class DB(object):
487487
pass
488488
489489
@pytest.fixture(scope="session")

doc/en/example/special.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ will be called ahead of running any tests::
2828

2929
# content of test_module.py
3030

31-
class TestHello:
31+
class TestHello(object):
3232
@classmethod
3333
def callme(cls):
3434
print ("callme called!")
@@ -39,7 +39,7 @@ will be called ahead of running any tests::
3939
def test_method2(self):
4040
print ("test_method1 called")
4141

42-
class TestOther:
42+
class TestOther(object):
4343
@classmethod
4444
def callme(cls):
4545
print ("callme other called")

doc/en/fixture.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ and instantiate an object ``app`` where we stick the already defined
557557

558558
import pytest
559559

560-
class App:
560+
class App(object):
561561
def __init__(self, smtp):
562562
self.smtp = smtp
563563

@@ -728,7 +728,7 @@ and declare its use in a test module via a ``usefixtures`` marker::
728728
import pytest
729729

730730
@pytest.mark.usefixtures("cleandir")
731-
class TestDirectoryInit:
731+
class TestDirectoryInit(object):
732732
def test_cwd_starts_empty(self):
733733
assert os.listdir(os.getcwd()) == []
734734
with open("myfile", "w") as f:
@@ -791,7 +791,7 @@ self-contained implementation of this idea::
791791

792792
import pytest
793793

794-
class DB:
794+
class DB(object):
795795
def __init__(self):
796796
self.intransaction = []
797797
def begin(self, name):
@@ -803,7 +803,7 @@ self-contained implementation of this idea::
803803
def db():
804804
return DB()
805805

806-
class TestClass:
806+
class TestClass(object):
807807
@pytest.fixture(autouse=True)
808808
def transact(self, request, db):
809809
db.begin(request.function.__name__)
@@ -861,7 +861,7 @@ into a conftest.py file **without** using ``autouse``::
861861
and then e.g. have a TestClass using it by declaring the need::
862862

863863
@pytest.mark.usefixtures("transact")
864-
class TestClass:
864+
class TestClass(object):
865865
def test_method1(self):
866866
...
867867

doc/en/funcarg_compare.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resources. Here is a basic example how we could implement
2424
a per-session Database object::
2525

2626
# content of conftest.py
27-
class Database:
27+
class Database(object):
2828
def __init__(self):
2929
print ("database instance created")
3030
def destroy(self):

doc/en/genapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import textwrap
22
import inspect
33

4-
class Writer:
4+
class Writer(object):
55
def __init__(self, clsname):
66
self.clsname = clsname
77

0 commit comments

Comments
 (0)