diff --git a/conftest.py b/conftest.py index 898fb537e..6c279a816 100644 --- a/conftest.py +++ b/conftest.py @@ -2,7 +2,7 @@ import sys from os.path import abspath, dirname, join -from tests.fixtures import (elasticapm_client, not_so_random, +from tests.fixtures import (elasticapm_client, instrument, not_so_random, sending_elasticapm_client, validating_httpserver) from tests.utils.compat import middleware_setting diff --git a/tests/fixtures.py b/tests/fixtures.py index 72772fa66..129aed99c 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -8,6 +8,7 @@ from pytest_localserver.http import ContentServer from werkzeug.wrappers import Request, Response +import elasticapm from elasticapm.base import Client ERRORS_SCHEMA = 'https://raw.githubusercontent.com/elastic/apm-server/master/docs/spec/errors/payload.json' @@ -117,3 +118,10 @@ def not_so_random(): random.seed(42) yield random.setstate(old_state) + + +@pytest.fixture() +def instrument(): + elasticapm.instrument() + yield + elasticapm.uninstrument() diff --git a/tests/instrumentation/botocore_tests.py b/tests/instrumentation/botocore_tests.py index fce568927..9a899694e 100644 --- a/tests/instrumentation/botocore_tests.py +++ b/tests/instrumentation/botocore_tests.py @@ -5,7 +5,7 @@ @mock.patch("botocore.endpoint.Endpoint.make_request") -def test_botocore_instrumentation(mock_make_request, elasticapm_client): +def test_botocore_instrumentation(mock_make_request, elasticapm_client, instrument): mock_response = mock.Mock() mock_response.status_code = 200 mock_make_request.return_value = (mock_response, {}) @@ -26,7 +26,7 @@ def test_botocore_instrumentation(mock_make_request, elasticapm_client): -def test_nonstandard_endpoint_url(elasticapm_client): +def test_nonstandard_endpoint_url(instrument, elasticapm_client): instrument = BotocoreInstrumentation() elasticapm_client.begin_transaction('test') module, method = BotocoreInstrumentation.instrument_list[0] diff --git a/tests/instrumentation/django_tests/template_tests.py b/tests/instrumentation/django_tests/template_tests.py index 29b17eca6..f355955d5 100644 --- a/tests/instrumentation/django_tests/template_tests.py +++ b/tests/instrumentation/django_tests/template_tests.py @@ -38,7 +38,7 @@ @mock.patch("elasticapm.traces.TransactionsStore.should_collect") -def test_template_rendering(should_collect, django_elasticapm_client, client): +def test_template_rendering(should_collect, instrument, django_elasticapm_client, client): should_collect.return_value = False with override_settings(**middleware_setting(django.VERSION, ['elasticapm.contrib.django.middleware.TracingMiddleware'])): @@ -67,7 +67,7 @@ def test_template_rendering(should_collect, django_elasticapm_client, client): @pytest.mark.skipif(django.VERSION < (1, 8), reason='Jinja2 support introduced with Django 1.8') @mock.patch("elasticapm.traces.TransactionsStore.should_collect") -def test_template_rendering_django18_jinja2(should_collect, django_elasticapm_client, client): +def test_template_rendering_django18_jinja2(should_collect, instrument, django_elasticapm_client, client): should_collect.return_value = False with override_settings( TEMPLATES=TEMPLATES, diff --git a/tests/instrumentation/jinja2_tests/jinja2_tests.py b/tests/instrumentation/jinja2_tests/jinja2_tests.py index 37cc0a2a5..b2785a70f 100644 --- a/tests/instrumentation/jinja2_tests/jinja2_tests.py +++ b/tests/instrumentation/jinja2_tests/jinja2_tests.py @@ -14,7 +14,7 @@ def jinja_env(): @mock.patch("elasticapm.traces.TransactionsStore.should_collect") -def test_from_file(should_collect, jinja_env, elasticapm_client): +def test_from_file(should_collect, instrument, jinja_env, elasticapm_client): should_collect.return_value = False elasticapm_client.begin_transaction("transaction.test") template = jinja_env.get_template('mytemplate.html') @@ -32,7 +32,7 @@ def test_from_file(should_collect, jinja_env, elasticapm_client): assert spans[0]['type'] == 'template.jinja2' -def test_from_string(elasticapm_client): +def test_from_string(instrument, elasticapm_client): elasticapm_client.begin_transaction("transaction.test") template = Template("