From bad7a0207fdd776307f29bc0563fcdc81bd57459 Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 24 May 2020 11:34:54 +0100 Subject: [PATCH 1/4] document new class instance per test --- doc/en/getting-started.rst | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 56057434e..55238ffa3 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -153,6 +153,55 @@ Once you develop multiple tests, you may want to group them into a class. pytest The first test passed and the second failed. You can easily see the intermediate values in the assertion to help you understand the reason for the failure. +Some reasons why grouping tests in a class can be useful is: + + * Structural or organizational reasons + * Sharing fixtures for tests only in that particular class + * Applying marks at the class level and having them implicitly apply to all tests + +Something to be aware of when grouping tests inside classes is that each test does not have the same instance of the class. +Having each test share the same class instance would be very detrimental to test isolation and would promote poor test practices. +This is outlined below: + +.. code-block:: python + + class TestClassDemoInstance: + def test_one(self): + assert 0 + + def test_two(self): + assert 0 + + +.. code-block:: pytest + + $ pytest -k TestClassDemoInstance -q + + FF [100%] + ============================================================================================================== FAILURES =============================================================================================================== + ___________________________________________________________________________________________________ TestClassDemoInstance.test_one ____________________________________________________________________________________________________ + + self = , request = > + + def test_one(self, request): + > assert 0 + E assert 0 + + testing\test_example.py:4: AssertionError + ___________________________________________________________________________________________________ TestClassDemoInstance.test_two ____________________________________________________________________________________________________ + + self = , request = > + + def test_two(self, request): + > assert 0 + E assert 0 + + testing\test_example.py:7: AssertionError + ======================================================================================================= short test summary info ======================================================================================================= + FAILED testing/test_example.py::TestClassDemoInstance::test_one - assert 0 + FAILED testing/test_example.py::TestClassDemoInstance::test_two - assert 0 + 2 failed in 0.17s + Request a unique temporary directory for functional tests -------------------------------------------------------------- From 568e00af15ea5e8783a4ee4eccf3ae7575119f6e Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 24 May 2020 11:43:29 +0100 Subject: [PATCH 2/4] fixing up formatting inline with a smaller shell and typos --- doc/en/getting-started.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 55238ffa3..7dac08892 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -153,9 +153,9 @@ Once you develop multiple tests, you may want to group them into a class. pytest The first test passed and the second failed. You can easily see the intermediate values in the assertion to help you understand the reason for the failure. -Some reasons why grouping tests in a class can be useful is: +Grouping tests in classes can be beneficial for the following reasons: - * Structural or organizational reasons + * Test organization * Sharing fixtures for tests only in that particular class * Applying marks at the class level and having them implicitly apply to all tests @@ -177,30 +177,32 @@ This is outlined below: $ pytest -k TestClassDemoInstance -q - FF [100%] - ============================================================================================================== FAILURES =============================================================================================================== - ___________________________________________________________________________________________________ TestClassDemoInstance.test_one ____________________________________________________________________________________________________ + FF [100%] + ================================== FAILURES =================================== + _______________________ TestClassDemoInstance.test_one ________________________ - self = , request = > + self = + request = > def test_one(self, request): > assert 0 E assert 0 testing\test_example.py:4: AssertionError - ___________________________________________________________________________________________________ TestClassDemoInstance.test_two ____________________________________________________________________________________________________ + _______________________ TestClassDemoInstance.test_two ________________________ - self = , request = > + self = + request = > def test_two(self, request): > assert 0 E assert 0 testing\test_example.py:7: AssertionError - ======================================================================================================= short test summary info ======================================================================================================= + =========================== short test summary info =========================== FAILED testing/test_example.py::TestClassDemoInstance::test_one - assert 0 FAILED testing/test_example.py::TestClassDemoInstance::test_two - assert 0 - 2 failed in 0.17s + 2 failed in 0.11s Request a unique temporary directory for functional tests -------------------------------------------------------------- From 4f93bc01af057e4bc08bce2c6674c0c7dce95002 Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 24 May 2020 16:31:51 +0100 Subject: [PATCH 3/4] update terminology of class individuality as per PR feedback --- doc/en/getting-started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 7dac08892..e8b033fe6 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -159,7 +159,7 @@ Grouping tests in classes can be beneficial for the following reasons: * Sharing fixtures for tests only in that particular class * Applying marks at the class level and having them implicitly apply to all tests -Something to be aware of when grouping tests inside classes is that each test does not have the same instance of the class. +Something to be aware of when grouping tests inside classes is that each has a unique instance of the class. Having each test share the same class instance would be very detrimental to test isolation and would promote poor test practices. This is outlined below: From 5061a47de8d1674a1ad6fa62500def7316a2bab0 Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 24 May 2020 16:33:17 +0100 Subject: [PATCH 4/4] add missing test text to docs --- doc/en/getting-started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index e8b033fe6..61a0baf19 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -159,7 +159,7 @@ Grouping tests in classes can be beneficial for the following reasons: * Sharing fixtures for tests only in that particular class * Applying marks at the class level and having them implicitly apply to all tests -Something to be aware of when grouping tests inside classes is that each has a unique instance of the class. +Something to be aware of when grouping tests inside classes is that each test has a unique instance of the class. Having each test share the same class instance would be very detrimental to test isolation and would promote poor test practices. This is outlined below: