def test_can_be_enabled(): """ Test that recording is enabled when APPMAP=true. """ Env.current.set("APPMAP", "true") assert appmap.enabled()
def test_reports_invalid(): """ Test that a parse error keeps recording from being enabled, and indicates that the config is not valid. """ assert not appmap.enabled() assert not Config().file_valid
def test_unnamed(client, events): client.get('/post/unnamed/5') assert appmap.enabled() # sanity check # unnamed captures in a re_path don't show up in the event's # message attribute. assert len(events[0].message) == 0
def test_skipped_when_overridden(self): appmap._implementation.initialize( env={ # pylint: disable=protected-access 'APPMAP': 'true', 'APPMAP_CONFIG': '/tmp/appmap.yml' }) assert not Config().name assert not appmap.enabled()
def test_config_no_message(caplog): """ Messages about a missing config should only be logged when recording is enabled """ assert Config().name is None assert not appmap.enabled() assert caplog.text is ""
def test_can_be_configured(): """ Test the happy path: APPMAP is true, appmap.yml is found, and the YAML is valid. """ assert appmap.enabled() c = Config() assert c.file_present assert c.file_valid
def check_default_config(self, expected_name): assert appmap.enabled() default_config = Config() assert default_config.name == expected_name assert len(default_config.packages) == 2 assert sorted(default_config.packages, key=lambda p: p['path']) == [{ 'path': 'package' }, { 'path': 'test' }]
def test_config_not_found(caplog): appmap._implementation.initialize( env={ # pylint: disable=protected-access 'APPMAP': 'true', 'APPMAP_CONFIG': 'notfound.yml' }) assert Config().name is None assert not Config().file_present assert not Config().file_valid assert not appmap.enabled() not_found = Path('notfound.yml').resolve() assert not not_found.exists() assert f'"{not_found}" is missing' in caplog.text
def setup_unittest(): if not appmap.enabled(): # Using this runner without enabling AppMap might not be what # the user intended, so issue a warning. logger.warning("AppMap disabled. Did you forget to set APPMAP=true?") return session = testing_framework.session('unittest') def get_test_location(cls, method_name): from appmap._implementation.utils import get_function_location fn = getattr(cls, method_name) return get_function_location(fn) # unittest.case._Outcome.testPartExecutor is used by all supported # versions of unittest to run test cases. `isTest` will be True when # the part is the actual test method, False when it's setUp or # teardown. @wrapt.patch_function_wrapper('unittest.case', '_Outcome.testPartExecutor') @contextmanager def testPartExecutor(wrapped, _, args, kwargs): def _args(test_case, *_, isTest=False, **__): return (test_case, isTest) test_case, is_test = _args(*args, **kwargs) already_recording = getattr(test_case, '_appmap_pytest_recording', None) if (not is_test) or already_recording: with wrapped(*args, **kwargs): yield return method_name = test_case.id().split('.')[-1] location = get_test_location(test_case.__class__, method_name) with session.record( test_case.__class__, method_name, location=location) as metadata: with wrapped(*args, **kwargs), testing_framework.collect_result_metadata(metadata): yield
def test_is_disabled_with_valid_config(): c = Config() assert c.file_present assert c.file_valid assert not appmap.enabled()
def test_is_disabled_when_false(): """Test that recording is disabled when APPMAP=false""" Env.current.set("APPMAP", "false") assert not appmap.enabled()
def test_is_disabled_when_unset(): """Test that recording is disabled when APPMAP is unset""" assert Env.current.get('APPMAP', None) is None assert not appmap.enabled()
def test_appmap_disabled(client): assert not appmap.enabled() res = client.get('/_appmap/record') assert res.status_code == 404
def test_can_be_enabled(self, monkeypatch): """Test that recording is enabled when APPMAP=true""" monkeypatch.setenv("APPMAP", "true") assert appmap.enabled()
def __init__(self, item): self.item = item @wrapt.decorator def __call__(self, wrapped, _, args, kwargs): item = self.item with item.session.appmap.record( item.cls, item.name, method_id=item.originalname, location=item.location) as metadata: with testing_framework.collect_result_metadata(metadata): return wrapped(*args, **kwargs) if appmap.enabled(): @pytest.hookimpl def pytest_sessionstart(session): session.appmap = testing_framework.session(name='pytest', version=pytest.__version__) @pytest.hookimpl def pytest_runtest_call(item): # The presence of a `_testcase` attribute on an item indicates # that it was created from a `unittest.TestCase`. An item # created from a TestCase has an `obj` attribute, assigned # during in setup, which holds the actual test # function. Wrapping that function will capture the recording # we want. `obj` gets unset during teardown, so there's no # chance of rewrapping it. # # However, depending on the user's configuration, `item.obj`
def test_is_disabled_when_false(self, monkeypatch): """Test that recording is disabled when APPMAP=false""" monkeypatch.setenv("APPMAP", "false") assert not appmap.enabled()
def test_is_disabled_when_unset(self, monkeypatch): """Test that recording is disabled when APPMAP is unset""" monkeypatch.delenv("APPMAP", raising=False) assert not appmap.enabled()