Skip to content

Commit

Permalink
New-style classes implemented for python 2.7 - pytest-dev#2147
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalTHEDUDE committed Feb 16, 2017
1 parent da828aa commit fb0b906
Show file tree
Hide file tree
Showing 61 changed files with 351 additions and 349 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Michael Aquilina
Michael Birtwell
Michael Droettboom
Michael Seifert
Michal Wajszczuk
Mike Lundy
Ned Batchelder
Neven Mundar
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Changes
-------

* 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
``__test__`` attribute to ``False`` in the class body (`#2007`_). Thanks
Expand Down Expand Up @@ -61,6 +61,7 @@ Changes
.. _@wheerd: https://github.com/wheerd
.. _@fogo: https://github.com/fogo
.. _@mandeep: https://github.com/mandeep
.. _@MichalTHEDUDE: https://github.com/MichalTHEDUDE
.. _@unsignedint: https://github.com/unsignedint
.. _@Kriechi: https://github.com/Kriechi

Expand Down
12 changes: 6 additions & 6 deletions _pytest/vendored_packages/pluggy.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def normalize_hookimpl_opts(opts):
opts.setdefault("optionalhook", False)


class _TagTracer:
class _TagTracer(object):
def __init__(self):
self._tag2proc = {}
self.writer = None
Expand Down Expand Up @@ -214,7 +214,7 @@ def setprocessor(self, tags, processor):
self._tag2proc[tags] = processor


class _TagTracerSub:
class _TagTracerSub(object):
def __init__(self, root, tags):
self.root = root
self.tags = tags
Expand Down Expand Up @@ -254,7 +254,7 @@ def _wrapped_call(wrap_controller, func):
return call_outcome.get_result()


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


class _TracedHookExecution:
class _TracedHookExecution(object):
def __init__(self, pluginmanager, before, after):
self.pluginmanager = pluginmanager
self.before = before
Expand Down Expand Up @@ -580,7 +580,7 @@ def subset_hook_caller(self, name, remove_plugins):
return orig


class _MultiCall:
class _MultiCall(object):
""" execute a call into multiple python functions/methods. """

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


class _HookRelay:
class _HookRelay(object):
""" hook holder object for performing 1:N hook calls where N is the number
of registered plugins.
Expand Down
2 changes: 1 addition & 1 deletion doc/en/assert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ provides an alternative explanation for ``Foo`` objects::
now, given this test module::

# content of test_foocompare.py
class Foo:
class Foo(object):
def __init__(self, val):
self.val = val

Expand Down
12 changes: 6 additions & 6 deletions doc/en/example/assertion/failure_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Bar(object):
def globf(x):
return x+1

class TestRaises:
class TestRaises(object):
def test_raises(self):
s = 'qwe'
raises(TypeError, "int(s)")
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_dynamic_compile_shows_nicely():



class TestMoreErrors:
class TestMoreErrors(object):
def test_complex_error(self):
def f():
return 44
Expand Down Expand Up @@ -213,23 +213,23 @@ def test_try_finally(self):
x = 0


class TestCustomAssertMsg:
class TestCustomAssertMsg(object):

def test_single_line(self):
class A:
class A(object):
a = 1
b = 2
assert A.a == b, "A.a appears not to be b"

def test_multiline(self):
class A:
class A(object):
a = 1
b = 2
assert A.a == b, "A.a appears not to be b\n" \
"or does not appear to be b\none of those"

def test_custom_repr(self):
class JSON:
class JSON(object):
a = 1
def __repr__(self):
return "This is JSON\n{\n 'foo': 'bar'\n}"
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/assertion/test_setup_flow_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def setup_module(module):
module.TestStateFullThing.classcount = 0

class TestStateFullThing:
class TestStateFullThing(object):
def setup_class(cls):
cls.classcount += 1

Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/attic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ example: specifying and selecting acceptance tests
def pytest_funcarg__accept(request):
return AcceptFixture(request)

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

class TestSpecialAcceptance:
class TestSpecialAcceptance(object):
def test_sometest(self, accept):
assert accept.tmpdir.join("special").check()

Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/costlysetup/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def setup(request):
yield setup
setup.finalize()

class CostlySetup:
class CostlySetup(object):
def __init__(self):
import time
print ("performing costly setup")
Expand Down
10 changes: 5 additions & 5 deletions doc/en/example/markers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You can "mark" a test function with custom metadata like this::
pass
def test_another():
pass
class TestClass:
class TestClass(object):
def test_method(self):
pass

Expand Down Expand Up @@ -242,7 +242,7 @@ its test methods::
# content of test_mark_classlevel.py
import pytest
@pytest.mark.webtest
class TestClass:
class TestClass(object):
def test_startup(self):
pass
def test_startup_and_more(self):
Expand All @@ -256,14 +256,14 @@ To remain backward-compatible with Python 2.4 you can also set a

import pytest

class TestClass:
class TestClass(object):
pytestmark = pytest.mark.webtest

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

import pytest

class TestClass:
class TestClass(object):
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]

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

@pytest.mark.glob("class", x=2)
class TestClass:
class TestClass(object):
@pytest.mark.glob("function", x=3)
def test_something(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/multipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def python1(request, tmpdir):
def python2(request, python1):
return Python(request.param, python1.picklefile)

class Python:
class Python(object):
def __init__(self, version, picklefile):
self.pythonpath = py.path.local.sysfind(version)
if not self.pythonpath:
Expand Down
8 changes: 4 additions & 4 deletions doc/en/example/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ only have to work a bit to construct the correct arguments for pytest's
scenario1 = ('basic', {'attribute': 'value'})
scenario2 = ('advanced', {'attribute': 'value2'})

class TestSampleWithScenarios:
class TestSampleWithScenarios(object):
scenarios = [scenario1, scenario2]

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

class DB1:
class DB1(object):
"one database object"
class DB2:
class DB2(object):
"alternative database object"

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

class TestClass:
class TestClass(object):
# a map specifying multiple argument sets for a test method
params = {
'test_equals': [dict(a=1, b=2), dict(a=3, b=3), ],
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/pythoncollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_function():
pass

class TestClass:
class TestClass(object):
def test_method(self):
pass
def test_anothermethod(self):
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/pythoncollection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

# content of check_myapp.py
class CheckMyApp:
class CheckMyApp(object):
def simple_check(self):
pass
def complex_check(self):
Expand Down
6 changes: 3 additions & 3 deletions doc/en/example/reportingdemo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_single_line(self):
class A:
class A(object):
a = 1
b = 2
> assert A.a == b, "A.a appears not to be b"
Expand All @@ -564,7 +564,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_multiline(self):
class A:
class A(object):
a = 1
b = 2
> assert A.a == b, "A.a appears not to be b\n" \
Expand All @@ -581,7 +581,7 @@ get on the terminal - we are working on that)::
self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef>
def test_custom_repr(self):
class JSON:
class JSON(object):
a = 1
def __repr__(self):
return "This is JSON\n{\n 'foo': 'bar'\n}"
Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ tests in a class. Here is a test module example:
import pytest
@pytest.mark.incremental
class TestUserHandling:
class TestUserHandling(object):
def test_login(self):
pass
def test_modification(self):
Expand Down Expand Up @@ -483,7 +483,7 @@ Here is an example for making a ``db`` fixture available in a directory:
# content of a/conftest.py
import pytest
class DB:
class DB(object):
pass
@pytest.fixture(scope="session")
Expand Down
4 changes: 2 additions & 2 deletions doc/en/example/special.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ will be called ahead of running any tests::

# content of test_module.py

class TestHello:
class TestHello(object):
@classmethod
def callme(cls):
print ("callme called!")
Expand All @@ -39,7 +39,7 @@ will be called ahead of running any tests::
def test_method2(self):
print ("test_method1 called")

class TestOther:
class TestOther(object):
@classmethod
def callme(cls):
print ("callme other called")
Expand Down
10 changes: 5 additions & 5 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ and instantiate an object ``app`` where we stick the already defined

import pytest

class App:
class App(object):
def __init__(self, smtp):
self.smtp = smtp

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

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

import pytest

class DB:
class DB(object):
def __init__(self):
self.intransaction = []
def begin(self, name):
Expand All @@ -803,7 +803,7 @@ self-contained implementation of this idea::
def db():
return DB()

class TestClass:
class TestClass(object):
@pytest.fixture(autouse=True)
def transact(self, request, db):
db.begin(request.function.__name__)
Expand Down Expand Up @@ -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::

@pytest.mark.usefixtures("transact")
class TestClass:
class TestClass(object):
def test_method1(self):
...

Expand Down
2 changes: 1 addition & 1 deletion doc/en/funcarg_compare.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resources. Here is a basic example how we could implement
a per-session Database object::

# content of conftest.py
class Database:
class Database(object):
def __init__(self):
print ("database instance created")
def destroy(self):
Expand Down
2 changes: 1 addition & 1 deletion doc/en/genapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import textwrap
import inspect

class Writer:
class Writer(object):
def __init__(self, clsname):
self.clsname = clsname

Expand Down
Loading

0 comments on commit fb0b906

Please sign in to comment.