From 640b2c0e132658206686a7b9df166cde204c164d Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Wed, 26 May 2021 09:06:47 -0700 Subject: [PATCH] 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. --- AUTHORS | 1 + doc/en/getting-started.rst | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/AUTHORS b/AUTHORS index b822d469a..7f5af5d92 100644 --- a/AUTHORS +++ b/AUTHORS @@ -62,6 +62,7 @@ Charles Machalow Charnjit SiNGH (CCSJ) Chris Lamb Chris NeJame +Chris Rose Christian Boelsen Christian Fetzer Christian Neumüller diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 2f082c35d..707087a9a 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -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 = - - def test_one(self): - > assert 0 - E assert 0 - - test_class_demo.py:3: AssertionError ______________________ TestClassDemoInstance.test_two ______________________ self = def test_two(self): - > assert 0 - E assert 0 + > assert self.value == 1 + E assert 0 == 1 + E + where 0 = .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.