-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
61 lines (52 loc) · 1.94 KB
/
conftest.py
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
55
56
57
58
59
60
61
import pytest
import os
import json
import allure
from datetime import datetime
# Environment configuration
@pytest.fixture(scope="session")
def env_config():
"""Load environment configuration"""
env = os.environ.get("TEST_ENV", "dev")
config_file = f"config.{env}.json"
if os.path.exists(config_file):
with open(config_file, 'r') as f:
return json.load(f)
return {}
# JWT token fixture
@pytest.fixture(scope="session")
def jwt_token(env_config):
"""Get JWT token for API calls"""
return env_config.get("jwt_token", "default_token")
# Setup allure environment info
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
"""Configure test environment"""
# Create results directory if it doesn't exist
if not os.path.exists("allure-results"):
os.makedirs("allure-results")
# Write environment info for Allure report
env_data = {
"Environment": os.environ.get("TEST_ENV", "dev"),
"Python Version": os.popen("python --version").read().strip(),
"Test Run Date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"Bot API URL": "https://stocksense-backend.onrender.com/api",
"Tester": os.environ.get("USER", "unknown")
}
with open(os.path.join("allure-results", "environment.properties"), 'w') as f:
for key, value in env_data.items():
f.write(f"{key}={value}\n")
# Custom logging for testimport pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
result = outcome.get_result()
# Only run this on the 'call' phase of the test (not setup/teardown)
if result.when == "call":
test_path = item.nodeid
metadata = f"Test: {test_path}\nExecution time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
allure.attach(
metadata,
name="Test Metadata",
attachment_type=allure.attachment_type.TEXT
)