fix(tests): purge theater/broken tests, fix Config argparse pollution, fix is_ad() false positive
PHASE 1 — STOP THE BLEEDING: - Delete 6 theater/dead test files (empty stubs, skipped placeholders) - Create root conftest.py to isolate Config/argparse from pytest sys.argv - Rewrite test_feed_loop_continuation.py: replace inspect.getsource() theater with real DopamineEngine behavior tests - Rewrite test_ad_detection.py: use existing XML fixtures instead of phantoms - Rewrite test_false_positive.py: use verified fixtures, caught REAL bug PRODUCTION FIX: - Fix is_ad() false positive: regex \bad\b was matching 'Create messaging ad' in DM inbox. Changed to exact label matching (text/desc must BE the ad marker, not merely contain it) Result: 34 FAILED + 4 ERRORS -> 0 FAILED, 178 PASSED, 3 SKIPPED
This commit is contained in:
38
tests/conftest.py
Normal file
38
tests/conftest.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Root Test Configuration — Global Guards Against Environmental Pollution
|
||||
=======================================================================
|
||||
|
||||
This conftest protects ALL tests from the #1 cause of mass failure:
|
||||
Config() constructor calling argparse.parse_known_args() which reads
|
||||
sys.argv (pytest's arguments) and crashes with SystemExit: 2.
|
||||
|
||||
Every test directory inherits these fixtures automatically.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _isolate_config_from_argparse(monkeypatch):
|
||||
"""Prevent Config() from reading sys.argv during tests.
|
||||
|
||||
Root cause: Config.__init__ calls self.parse_args() which calls
|
||||
self.parser.parse_known_args(). In pytest, sys.argv contains
|
||||
pytest flags like '--ignore=...' which argparse interprets as
|
||||
Config arguments, causing SystemExit: 2.
|
||||
|
||||
Fix: Temporarily set sys.argv to a minimal list so argparse
|
||||
doesn't choke on pytest's arguments.
|
||||
"""
|
||||
monkeypatch.setattr(sys, "argv", ["test_runner"])
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════
|
||||
# Pytest Markers Registration
|
||||
# ═══════════════════════════════════════════════════════
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line("markers", "live_llm: requires a running local LLM (Ollama)")
|
||||
Reference in New Issue
Block a user