Skip to content

Commit f277944

Browse files
committed
tests: Modify gevent_autotrace
Signed-off-by: Varsha GS <varsha.gs@ibm.com>
1 parent f0f7a18 commit f277944

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
collect_ignore_glob = [
2929
"*collector/test_gcr*",
3030
"*agent/test_google*",
31-
"*test_gevent_autotrace*"
3231
]
3332

3433
# ppc64le and s390x have limitations with some supported libraries.
@@ -54,7 +53,7 @@
5453
if not os.environ.get("GEVENT_STARLETTE_TEST"):
5554
collect_ignore_glob.extend(
5655
[
57-
"*test_gevent.py",
56+
"*test_gevent*",
5857
]
5958
)
6059

tests/frameworks/test_gevent_autotrace.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@
33

44
import importlib
55
import os
6-
import unittest
7-
import socket
6+
import pytest
87

98
import gevent
109
from gevent import monkey
1110
from instana import apply_gevent_monkey_patch
1211

12+
# Teardown not working as expected, run each testcase separately
13+
class TestGEventAutoTrace:
1314

14-
class TestGEventAutoTrace(unittest.TestCase):
15-
def setUp(self):
15+
@pytest.fixture(autouse=True)
16+
def setup_environment(self):
17+
"""Setup test environment before each test"""
1618
# Ensure that the test suite is operational even when Django is installed
1719
# but not running or configured
1820
os.environ['DJANGO_SETTINGS_MODULE'] = ''
19-
21+
2022
self.default_patched_modules = ('socket', 'time', 'select', 'os',
2123
'threading', 'ssl', 'subprocess', 'signal', 'queue',)
22-
23-
def tearDown(self):
24+
25+
yield
26+
27+
# Teardown
2428
if os.environ.get('INSTANA_GEVENT_MONKEY_OPTIONS'):
2529
os.environ.pop('INSTANA_GEVENT_MONKEY_OPTIONS')
26-
30+
2731
# Clean up after gevent monkey patches, by restore from the saved dict
2832
for modname in monkey.saved.keys():
2933
try:
@@ -35,37 +39,34 @@ def tearDown(self):
3539
pass
3640
monkey.saved = {}
3741

38-
3942
def test_default_patch_all(self):
4043
apply_gevent_monkey_patch()
4144
for module_name in self.default_patched_modules:
42-
self.assertTrue(monkey.is_module_patched(module_name),
43-
f"{module_name} is not patched")
45+
assert monkey.is_module_patched(module_name), f"{module_name} is not patched"
4446

4547
def test_instana_monkey_options_only_time(self):
4648
os.environ['INSTANA_GEVENT_MONKEY_OPTIONS'] = (
4749
'time,no-socket,no-select,no-os,no-select,no-threading,no-os,'
4850
'no-ssl,no-subprocess,''no-signal,no-queue')
4951
apply_gevent_monkey_patch()
50-
51-
self.assertTrue(monkey.is_module_patched('time'), "time module is not patched")
52+
53+
assert monkey.is_module_patched('time'), "time module is not patched"
5254
not_patched_modules = (m for m in self.default_patched_modules if m not in ('time', 'threading'))
53-
55+
5456
for module_name in not_patched_modules:
55-
self.assertFalse(monkey.is_module_patched(module_name),
56-
f"{module_name} is patched, when it shouldn't be")
57-
57+
assert not monkey.is_module_patched(module_name), \
58+
f"{module_name} is patched, when it shouldn't be"
5859

5960
def test_instana_monkey_options_only_socket(self):
6061
os.environ['INSTANA_GEVENT_MONKEY_OPTIONS'] = (
6162
'--socket, --no-time, --no-select, --no-os, --no-queue, --no-threading,'
6263
'--no-os, --no-ssl, no-subprocess, --no-signal, --no-select,')
6364
apply_gevent_monkey_patch()
64-
65-
self.assertTrue(monkey.is_module_patched('socket'), "socket module is not patched")
65+
66+
assert monkey.is_module_patched('socket'), "socket module is not patched"
6667
not_patched_modules = (m for m in self.default_patched_modules if m not in ('socket', 'threading'))
67-
68+
6869
for module_name in not_patched_modules:
69-
self.assertFalse(monkey.is_module_patched(module_name),
70-
f"{module_name} is patched, when it shouldn't be")
70+
assert not monkey.is_module_patched(module_name), \
71+
f"{module_name} is patched, when it shouldn't be"
7172

0 commit comments

Comments
 (0)