Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a8c2cf3

Browse files
committedApr 28, 2025·
CTRL+E
1 parent 3e1f006 commit a8c2cf3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎tests/test_trade.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@
2525
TEST_FEE = 1.5
2626

2727

28+
def is_headless() -> bool:
29+
"""Check if running in headless mode."""
30+
return os.environ.get("HEADLESS_MODE", "false").lower() == "true"
31+
32+
2833
@pytest.fixture(scope="module", autouse=True)
2934
def setup_teardown() -> Generator[None, None, None]:
3035
"""Set up and tear down MetaTrader5 connection for the test module."""
36+
if is_headless():
37+
logger.info("Running in headless mode - skipping MT5 initialization")
38+
yield
39+
return
40+
3141
init_result = Mt5.initialize()
3242

3343
if not init_result:
@@ -487,3 +497,10 @@ def test_close_position(trade: Trade) -> None:
487497
except Exception as e:
488498
logger.exception("Error during position test")
489499
raise
500+
501+
502+
@pytest.fixture(autouse=True)
503+
def skip_real_trading_in_headless(request) -> None:
504+
"""Skip real trading tests in headless mode."""
505+
if is_headless() and request.node.get_closest_marker("real_trading"):
506+
pytest.skip("Skipping real trading test in headless mode")

0 commit comments

Comments
 (0)