Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit a911082

Browse files
committed
[testing] Remove nose usage
This has been deprecated and unmaintained for years; stop installing it. - Replaces `nose.tools.ok_` with `assert` - Replaces `nose.tools.eq_` with `assert ==` - Replaces `nose.tools.assert_raises` with `pytest.raises` - Add missing unittest.TestCase inheritance in some place - Only install requests-mock for requests_contrib scenarios; this modules has a pytest plugin that gets loaded otherwise and pre-load - `requests`, making some test checking for module load ordering fail.
1 parent 549899e commit a911082

File tree

96 files changed

+3382
-3529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3382
-3529
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ htmlcov/
4141
.coverage
4242
.coverage.*
4343
.cache
44-
nosetests.xml
4544
coverage.xml
4645
*,cover
4746
.hypothesis/

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
[nosetests]
2-
verbosity=1
3-
41
[bdist_wheel]
52
universal=1

tests/commands/ddtrace_run_argv.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from nose.tools import eq_
21
import sys
32

43
if __name__ == '__main__':
5-
eq_(sys.argv[1:], ['foo', 'bar'])
4+
assert sys.argv[1:] == ['foo', 'bar']
65
print('Test success')

tests/commands/ddtrace_run_debug.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import tracer
22

3-
from nose.tools import ok_
4-
53
if __name__ == '__main__':
6-
ok_(tracer.debug_logging)
4+
assert tracer.debug_logging
75
print("Test success")
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from ddtrace import tracer, monkey
22

3-
from nose.tools import ok_, eq_
4-
53
if __name__ == '__main__':
6-
ok_(not tracer.enabled)
7-
eq_(len(monkey.get_patched_modules()), 0)
4+
assert not tracer.enabled
5+
assert len(monkey.get_patched_modules()) == 0
86
print("Test success")

tests/commands/ddtrace_run_enabled.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import tracer
22

3-
from nose.tools import ok_
4-
53
if __name__ == '__main__':
6-
ok_(tracer.enabled)
4+
assert tracer.enabled
75
print("Test success")

tests/commands/ddtrace_run_env.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import tracer
22

3-
from nose.tools import eq_
4-
53
if __name__ == '__main__':
6-
eq_(tracer.tags['env'], 'test')
4+
assert tracer.tags['env'] == 'test'
75
print('Test success')
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from ddtrace import tracer
22

3-
from nose.tools import eq_
4-
53
if __name__ == '__main__':
6-
eq_(tracer.writer.api.hostname, "172.10.0.1")
7-
eq_(tracer.writer.api.port, 8120)
4+
assert tracer.writer.api.hostname == "172.10.0.1"
5+
assert tracer.writer.api.port == 8120
86
print("Test success")

tests/commands/ddtrace_run_integration.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,38 @@
99
from tests.contrib.config import REDIS_CONFIG
1010
from tests.test_tracer import DummyWriter
1111

12-
from nose.tools import eq_, ok_
13-
1412
if __name__ == '__main__':
1513
r = redis.Redis(port=REDIS_CONFIG['port'])
1614
pin = Pin.get_from(r)
17-
ok_(pin)
18-
eq_(pin.app, 'redis')
19-
eq_(pin.service, 'redis')
15+
assert pin
16+
assert pin.app == 'redis'
17+
assert pin.service == 'redis'
2018

2119
pin.tracer.writer = DummyWriter()
2220
r.flushall()
2321
spans = pin.tracer.writer.pop()
2422

25-
eq_(len(spans), 1)
26-
eq_(spans[0].service, 'redis')
27-
eq_(spans[0].resource, 'FLUSHALL')
23+
assert len(spans) == 1
24+
assert spans[0].service == 'redis'
25+
assert spans[0].resource == 'FLUSHALL'
2826

2927
long_cmd = "mget %s" % " ".join(map(str, range(1000)))
3028
us = r.execute_command(long_cmd)
3129

3230
spans = pin.tracer.writer.pop()
33-
eq_(len(spans), 1)
31+
assert len(spans) == 1
3432
span = spans[0]
35-
eq_(span.service, 'redis')
36-
eq_(span.name, 'redis.command')
37-
eq_(span.span_type, 'redis')
38-
eq_(span.error, 0)
33+
assert span.service == 'redis'
34+
assert span.name == 'redis.command'
35+
assert span.span_type == 'redis'
36+
assert span.error == 0
3937
meta = {
4038
'out.host': u'localhost',
4139
'out.port': str(REDIS_CONFIG['port']),
4240
'out.redis_db': u'0',
4341
}
4442
for k, v in meta.items():
45-
eq_(span.get_tag(k), v)
43+
assert span.get_tag(k) == v
4644

4745
assert span.get_tag('redis.raw_command').startswith(u'mget 0 1 2 3')
4846
assert span.get_tag('redis.raw_command').endswith(u'...')
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import tracer
22

3-
from nose.tools import ok_
4-
53
if __name__ == '__main__':
6-
ok_(not tracer.debug_logging)
4+
assert not tracer.debug_logging
75
print("Test success")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import monkey
22

3-
from nose.tools import ok_
4-
53
if __name__ == '__main__':
6-
ok_('redis' in monkey.get_patched_modules())
4+
assert 'redis' in monkey.get_patched_modules()
75
print("Test success")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from ddtrace import tracer
22

3-
from nose.tools import ok_
4-
53
if __name__ == '__main__':
6-
ok_(tracer.priority_sampler is not None)
4+
assert tracer.priority_sampler is not None
75
print("Test success")

tests/commands/ddtrace_run_service.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
22

3-
from nose.tools import eq_
4-
53
if __name__ == '__main__':
6-
eq_(os.environ['DATADOG_SERVICE_NAME'], 'my_test_service')
4+
assert os.environ['DATADOG_SERVICE_NAME'] == 'my_test_service'
75
print('Test success')
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import sys
2-
from nose.tools import ok_
32

43

54
if __name__ == '__main__':
65
# detect if `-S` is used
76
suppress = len(sys.argv) == 2 and sys.argv[1] == '-S'
87
if suppress:
9-
ok_('sitecustomize' not in sys.modules)
8+
assert 'sitecustomize' not in sys.modules
109
else:
11-
ok_('sitecustomize' in sys.modules)
10+
assert 'sitecustomize' in sys.modules
1211

1312
# ensure the right `sitecustomize` will be imported
1413
import sitecustomize
15-
ok_(sitecustomize.CORRECT_IMPORT)
14+
assert sitecustomize.CORRECT_IMPORT
1615
print('Test success')

tests/commands/test_runner.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import subprocess
55
import unittest
66

7-
from nose.tools import ok_
8-
97
from ..util import inject_sitecustomize
108

119

@@ -189,7 +187,7 @@ def test_sitecustomize_without_ddtrace_run_command(self):
189187
)
190188
# `out` contains the `loaded` status of the module
191189
result = out[:-1] == b'True'
192-
ok_(result)
190+
assert result
193191

194192
def test_sitecustomize_run(self):
195193
# [Regression test]: ensure users `sitecustomize.py` is properly loaded,

tests/contrib/aiobotocore/py35/test.py

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# flake8: noqa
22
# DEV: Skip linting, we lint with Python 2, we'll get SyntaxErrors from `async`
33
import aiobotocore
4-
from nose.tools import eq_
54

65
from ddtrace.contrib.aiobotocore.patch import patch, unpatch
76

@@ -42,32 +41,32 @@ async def test_response_context_manager(self):
4241
pre_08 = int(version[0]) == 0 and int(version[1]) < 8
4342
# Version 0.8+ generates only one span for reading an object.
4443
if pre_08:
45-
eq_(len(traces), 2)
46-
eq_(len(traces[0]), 1)
47-
eq_(len(traces[1]), 1)
44+
assert len(traces) == 2
45+
assert len(traces[0]) == 1
46+
assert len(traces[1]) == 1
4847

4948
span = traces[0][0]
50-
eq_(span.get_tag('aws.operation'), 'GetObject')
51-
eq_(span.get_tag('http.status_code'), '200')
52-
eq_(span.service, 'aws.s3')
53-
eq_(span.resource, 's3.getobject')
49+
assert span.get_tag('aws.operation') == 'GetObject'
50+
assert span.get_tag('http.status_code') == '200'
51+
assert span.service == 'aws.s3'
52+
assert span.resource == 's3.getobject'
5453

5554
read_span = traces[1][0]
56-
eq_(read_span.get_tag('aws.operation'), 'GetObject')
57-
eq_(read_span.get_tag('http.status_code'), '200')
58-
eq_(read_span.service, 'aws.s3')
59-
eq_(read_span.resource, 's3.getobject')
60-
eq_(read_span.name, 's3.command.read')
55+
assert read_span.get_tag('aws.operation') == 'GetObject'
56+
assert read_span.get_tag('http.status_code') == '200'
57+
assert read_span.service == 'aws.s3'
58+
assert read_span.resource == 's3.getobject'
59+
assert read_span.name == 's3.command.read'
6160
# enforce parenting
62-
eq_(read_span.parent_id, span.span_id)
63-
eq_(read_span.trace_id, span.trace_id)
61+
assert read_span.parent_id == span.span_id
62+
assert read_span.trace_id == span.trace_id
6463
else:
65-
eq_(len(traces[0]), 1)
66-
eq_(len(traces[0]), 1)
64+
assert len(traces[0]) == 1
65+
assert len(traces[0]) == 1
6766

6867
span = traces[0][0]
69-
eq_(span.get_tag('aws.operation'), 'GetObject')
70-
eq_(span.get_tag('http.status_code'), '200')
71-
eq_(span.service, 'aws.s3')
72-
eq_(span.resource, 's3.getobject')
73-
eq_(span.name, 's3.command')
68+
assert span.get_tag('aws.operation') == 'GetObject'
69+
assert span.get_tag('http.status_code') == '200'
70+
assert span.service == 'aws.s3'
71+
assert span.resource == 's3.getobject'
72+
assert span.name == 's3.command'

0 commit comments

Comments
 (0)