import sys import logging import pytest from configparser import ConfigParser from threading import Lock, Event from appengine import Commands, AppEngineException, AEErrs class SampleModule(Commands): """Concrete Commands subclass used across tests.""" def cmd_add(self, a, b): """Add two numbers. Args: a: First number. b: Second number. Returns: float: Sum of a and b. """ return float(a) + float(b) def cmd_raise_ae(self): """Raise an AppEngineException.""" raise AppEngineException(AEErrs.INVALID_PARAMS, "test error") def cmd_raise_generic(self): """Raise a generic exception.""" raise RuntimeError("boom") @pytest.fixture def log(): return logging.getLogger("test") @pytest.fixture def sample_module(log): m = SampleModule(None, log) m.lock = Lock() m.cmods = {} return m @pytest.fixture(autouse=True) def clean_imported_modules(): """Remove dynamically imported cmds_* modules after each test.""" yield to_remove = [k for k in sys.modules if k.startswith("cmds_")] for k in to_remove: del sys.modules[k]