You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/en/getting-started.rst
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,55 @@ Once you develop multiple tests, you may want to group them into a class. pytest
153
153
154
154
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.
155
155
156
+
Some reasons why grouping tests in a class can be useful is:
157
+
158
+
* Structural or organizational reasons
159
+
* Sharing fixtures for tests only in that particular class
160
+
* Applying marks at the class level and having them implicitly apply to all tests
161
+
162
+
Something to be aware of when grouping tests inside classes is that each test does not have the same instance of the class.
163
+
Having each test share the same class instance would be very detrimental to test isolation and would promote poor test practices.
self = <test_example.TestClassDemoInstance object at 0x000001F001A54908>, request = <FixtureRequest for <Function test_two>>
194
+
195
+
def test_two(self, request):
196
+
> assert 0
197
+
E assert 0
198
+
199
+
testing\test_example.py:7: AssertionError
200
+
======================================================================================================= short test summary info =======================================================================================================
0 commit comments