-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
54 lines (41 loc) · 1.13 KB
/
conftest.py
File metadata and controls
54 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Shared pytest fixtures"""
import pytest
from pathlib import Path
import tempfile
from openpyxl import Workbook
@pytest.fixture
def temp_excel_file():
"""Provides a temporary Excel file path that will be cleaned up after use"""
with tempfile.NamedTemporaryFile(suffix=".xlsx", delete=False) as tmp:
file_path = Path(tmp.name)
yield str(file_path)
# Cleanup
if file_path.exists():
file_path.unlink()
@pytest.fixture
def sample_workbook(temp_excel_file):
"""Creates a sample workbook with data for testing"""
wb = Workbook()
ws = wb.active
ws.title = "Sheet1"
# Add some sample data
ws["A1"] = "Name"
ws["B1"] = "Age"
ws["C1"] = "City"
ws["A2"] = "Alice"
ws["B2"] = 30
ws["C2"] = "New York"
ws["A3"] = "Bob"
ws["B3"] = 25
ws["C3"] = "Los Angeles"
ws["A4"] = "Charlie"
ws["B4"] = 35
ws["C4"] = "Chicago"
wb.save(temp_excel_file)
wb.close()
yield temp_excel_file
@pytest.fixture
def temp_dir():
"""Provides a temporary directory for file operations"""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)