Skip to content

Commit 640b2c0

Browse files
offbyoneChris Rose
authored andcommitted
Make the test class instance behaviour clearer
In the "Getting Started" doc, the test class instance example for instance sharing doesn't actually demonstrate anything about the reinstantiation of the class. This change shows clearly how the instance data isn't retained between test runs.
1 parent 1d5ee4d commit 640b2c0

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Charles Machalow
6262
Charnjit SiNGH (CCSJ)
6363
Chris Lamb
6464
Chris NeJame
65+
Chris Rose
6566
Christian Boelsen
6667
Christian Fetzer
6768
Christian Neumüller

doc/en/getting-started.rst

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,40 +169,34 @@ This is outlined below:
169169
170170
# content of test_class_demo.py
171171
class TestClassDemoInstance:
172+
value = 0
173+
172174
def test_one(self):
173-
assert 0
175+
self.value = 1
176+
assert self.value == 1
174177
175178
def test_two(self):
176-
assert 0
179+
assert self.value == 1
177180
178181
179182
.. code-block:: pytest
180183
181184
$ pytest -k TestClassDemoInstance -q
182-
FF [100%]
185+
.F [100%]
183186
================================= FAILURES =================================
184-
______________________ TestClassDemoInstance.test_one ______________________
185-
186-
self = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>
187-
188-
def test_one(self):
189-
> assert 0
190-
E assert 0
191-
192-
test_class_demo.py:3: AssertionError
193187
______________________ TestClassDemoInstance.test_two ______________________
194188
195189
self = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>
196190
197191
def test_two(self):
198-
> assert 0
199-
E assert 0
192+
> assert self.value == 1
193+
E assert 0 == 1
194+
E + where 0 = <test_class_demo.TestClassDemoInstance object at 0xdeadbeef>.value
200195
201-
test_class_demo.py:6: AssertionError
196+
test_class_demo.py:9: AssertionError
202197
========================= short test summary info ==========================
203-
FAILED test_class_demo.py::TestClassDemoInstance::test_one - assert 0
204-
FAILED test_class_demo.py::TestClassDemoInstance::test_two - assert 0
205-
2 failed in 0.12s
198+
FAILED test_class_demo.py::TestClassDemoInstance::test_two - assert 0 == 1
199+
1 failed, 1 passed in 0.04s
206200
207201
Note that attributes added at class level are *class attributes*, so they will be shared between tests.
208202

0 commit comments

Comments
 (0)