Skip to content

Commit c8ac1b8

Browse files
Add pytest test functions with fixtures
This test file includes multiple test functions and uses pytest fixtures for setup and teardown. Signed-off-by: Fabiana ⚡️ Campanari <[email protected]>
1 parent 0e7e9b8 commit c8ac1b8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test_code.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
#Test file for pytest. This example includes several test functions and uses pytest fixtures for setup and teardown.
4+
5+
import pytest
6+
# Setup for configuration and cleanup
7+
@pytest.fixture
8+
def setup_data():
9+
print("\nSetup")
10+
data = {"key1": "value1", "key2": "value2"}
11+
yield data
12+
print("\nCleanup")
13+
14+
# Test function using the fixture
15+
def test_key1(setup_data):
16+
assert setup_data["key1"] == "value1"
17+
18+
# Another test function using the fixture
19+
def test_key2(setup_data):
20+
assert setup_data["key2"] == "value2"
21+
22+
# Test function without using the fixture
23+
def test_addition():
24+
assert 1 + 1 == 2
25+
26+

0 commit comments

Comments
 (0)