File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
source-code/testing/PyTest/Fixtures Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ A simple illustration of using fixtures in pytest.
44## What is it?
551 . ` test_data_structure.py ` : creates a test and a module fixture, and
66 defines three tests, one of which is intended to fail.
7+ 1 . ` test_list.py ` : creates a list and tests whether ` pop ` and ` append ` work,
8+ illustrates the advantage of ` function ` scope fixtures.
791 . ` test_wc.py ` : creates a module fixture that will be torn down when
810 the test is done.
911
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+
4+ @pytest .fixture
5+ def non_empty_list ():
6+ return list (range (5 ))
7+
8+
9+ def test_pop (non_empty_list ):
10+ orig_len = len (non_empty_list )
11+ assert non_empty_list [- 1 ] == orig_len - 1
12+ non_empty_list .pop ()
13+ assert len (non_empty_list ) == orig_len - 1
14+ assert non_empty_list [- 1 ] == orig_len - 2
15+
16+
17+ def test_append (non_empty_list ):
18+ orig_len = len (non_empty_list )
19+ assert non_empty_list [- 1 ] == orig_len - 1
20+ non_empty_list .append (orig_len )
21+ assert len (non_empty_list ) == orig_len + 1
22+ assert non_empty_list [- 1 ] == orig_len
You can’t perform that action at this time.
0 commit comments