Example of how to check some conditions when ALL test suites finished (or enforce some test running at the end of session). This may be useful to ensure that you have tested all functions of some module whose interface can change in future. The code: from pytest import fixture Data = dict ( cnt = 0 ) @fixture ( scope = 'session' ) def data_0 (): yield Data # (this will be done AFTER all tests below) assert Data [ 'cnt' ] == 3 , f 'data-cnt: { Data [ "cnt" ] } ' @fixture def data ( data_0 ): Data [ 'cnt' ] += 1 return Data [ 'cnt' ] def test_11 ( data ): print () print ( 'test-11:' , data ) def test_12 ( data ): print () print ( 'test-12:' , data ) Output: ERROR test_1.py::test_12 - AssertionError: data-cnt: 2 _________ Other articles ~ programming
Comments
Post a Comment