Skip to content

Make the test class instance behaviour clearer #8704

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Charles Machalow
Charnjit SiNGH (CCSJ)
Chris Lamb
Chris NeJame
Chris Rose
Christian Boelsen
Christian Fetzer
Christian Neumüller
Expand Down
30 changes: 12 additions & 18 deletions doc/en/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,40 +169,34 @@ This is outlined below:

# content of test_class_demo.py
class TestClassDemoInstance:
value = 0

def test_one(self):
assert 0
self.value = 1
assert self.value == 1

def test_two(self):
assert 0
assert self.value == 1


.. code-block:: pytest

$ pytest -k TestClassDemoInstance -q
FF [100%]
.F [100%]
================================= FAILURES =================================
______________________ TestClassDemoInstance.test_one ______________________

self = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>

def test_one(self):
> assert 0
E assert 0

test_class_demo.py:3: AssertionError
______________________ TestClassDemoInstance.test_two ______________________

self = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>

def test_two(self):
> assert 0
E assert 0
> assert self.value == 1
E assert 0 == 1
E + where 0 = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>.value

test_class_demo.py:6: AssertionError
test_class_demo.py:9: AssertionError
========================= short test summary info ==========================
FAILED test_class_demo.py::TestClassDemoInstance::test_one - assert 0
FAILED test_class_demo.py::TestClassDemoInstance::test_two - assert 0
2 failed in 0.12s
FAILED test_class_demo.py::TestClassDemoInstance::test_two - assert 0 == 1
1 failed, 1 passed in 0.04s

Note that attributes added at class level are *class attributes*, so they will be shared between tests.

Expand Down