Coverage for tests/conftest.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-23 23:00 +0800

1"""pytest 配置""" 

2 

3import os 

4import sys 

5import tempfile 

6import pytest 

7 

8# 將專案根目錄加入 Python 路徑 

9project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

10sys.path.insert(0, project_root) 

11 

12 

13@pytest.fixture 

14def temp_dir(): 

15 """提供臨時目錄""" 

16 temp_dir = tempfile.mkdtemp() 

17 yield temp_dir 

18 

19 # 清理 

20 import shutil 

21 shutil.rmtree(temp_dir, ignore_errors=True) 

22 

23 

24@pytest.fixture 

25def sample_user_data(): 

26 """提供示例用戶數據""" 

27 return { 

28 "name": "Alice", 

29 "email": "alice@example.com", 

30 "age": 30 

31 } 

32 

33 

34@pytest.fixture 

35def sample_product_data(): 

36 """提供示例產品數據""" 

37 return { 

38 "name": "筆記本電腦", 

39 "description": "高性能筆記本電腦", 

40 "price": 25000.0, 

41 "category": "電子產品" 

42 }