Skip to content

Commit 1c2fb7a

Browse files
Replace nose with pytest (#836)
* Use pytest instead of nose * Remove nose dependencies * "setup.py test" is deprecated * More removal of nose usage * Update to pytest * Make ipv6 tests use pytest * Make pytest happier with the name * Upgrade coverage.py which seems to help with the 3.11 errors * Link to doctests issue * Switch to name that pytest will detect as being a test module. * Expose tests to pytest * Fix style --------- Co-authored-by: Itamar Turner-Trauring <itamar@pythonspeed.com>
1 parent 97dc606 commit 1c2fb7a

11 files changed

+49
-78
lines changed

doc/testing.rst

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
Testing Eventlet
22
================
33

4-
Eventlet is tested using `Nose <http://somethingaboutorange.com/mrl/projects/nose/>`_. To run tests, simply install nose, and then, in the eventlet tree, do:
4+
Eventlet is tested using `Pytest <https://pytest/>`_. To run tests, simply install pytest, and then, in the eventlet tree, do:
55

66
.. code-block:: sh
77
8-
$ python setup.py test
8+
$ pytest
99
10-
If you want access to all the nose plugins via command line, you can run:
11-
12-
.. code-block:: sh
13-
14-
$ python setup.py nosetests
15-
16-
Lastly, you can just use nose directly if you want:
17-
18-
.. code-block:: sh
19-
20-
$ nosetests
21-
22-
That's it! The output from running nose is the same as unittest's output, if the entire directory was one big test file.
10+
That's it!
2311

2412
Many tests are skipped based on environmental factors; for example, it makes no sense to test kqueue-specific functionality when your OS does not support it. These are printed as S's during execution, and in the summary printed after the tests run it will tell you how many were skipped.
2513

@@ -30,9 +18,9 @@ To run the doctests included in many of the eventlet modules, use this command:
3018

3119
.. code-block :: sh
3220
33-
$ nosetests --with-doctest eventlet/*.py
21+
$ pytest --doctest-modules eventlet/
3422
35-
Currently there are 16 doctests.
23+
The doctests currently `do not pass <https://github.com/eventlet/eventlet/issues/837>`_.
3624

3725

3826
Testing Eventlet Hubs
@@ -42,7 +30,7 @@ When you run the tests, Eventlet will use the most appropriate hub for the curre
4230

4331
.. code-block:: sh
4432
45-
$ EVENTLET_HUB=epolls nosetests
33+
$ EVENTLET_HUB=epolls pytest
4634
4735
See :ref:`understanding_hubs` for the full list of hubs.
4836

@@ -62,11 +50,11 @@ If you are writing a test that involves a client connecting to a spawned server,
6250
Coverage
6351
--------
6452

65-
Coverage.py is an awesome tool for evaluating how much code was exercised by unit tests. Nose supports it if both are installed, so it's easy to generate coverage reports for eventlet. Here's how:
53+
Coverage.py is an awesome tool for evaluating how much code was exercised by unit tests. pytest supports it pytest-cov is installed, so it's easy to generate coverage reports for eventlet. Here's how:
6654

6755
.. code-block:: sh
6856
69-
nosetests --with-coverage --cover-package=eventlet
57+
pytest --cov=eventlet
7058
7159
After running the tests to completion, this will emit a huge wodge of module names and line numbers. For some reason, the ``--cover-inclusive`` option breaks everything rather than serving its purpose of limiting the coverage to the local files, so don't use that.
7260

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
'README.rst'
3232
)
3333
).read(),
34-
test_suite='nose.collector',
3534
classifiers=[
3635
"Development Status :: 4 - Beta",
3736
"Intended Audience :: Developers",

tests/README

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
The tests are intended to be run using Nose.
2-
http://somethingaboutorange.com/mrl/projects/nose/
1+
The tests are intended to be run using pytest.
32

4-
To run tests, simply install nose, and then, in the eventlet tree, do:
5-
$ nosetests
6-
7-
That's it! Its output is the same as unittest's output. It tends to emit a lot of tracebacks from various poorly-behaving tests, but they still (generally) pass.
3+
To run tests, simply install pytest, and then, in the eventlet tree, do:
4+
$ pytest

tests/__init__.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import unittest
2121
import warnings
2222

23-
from nose.plugins.skip import SkipTest
23+
from unittest import SkipTest
2424

2525
import eventlet
2626
from eventlet import tpool
@@ -213,7 +213,6 @@ def assert_less_than_equal(self, a, b, msg=None):
213213
def check_idle_cpu_usage(duration, allowed_part):
214214
if resource is None:
215215
# TODO: use https://code.google.com/p/psutil/
216-
from nose.plugins.skip import SkipTest
217216
raise SkipTest('CPU usage testing not supported (`import resource` failed)')
218217

219218
r1 = resource.getrusage(resource.RUSAGE_SELF)
@@ -392,18 +391,6 @@ def capture_stderr():
392391
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
393392

394393

395-
def test_run_python_timeout():
396-
output = run_python('', args=('-c', 'import time; time.sleep(0.5)'), timeout=0.1)
397-
assert output.endswith(b'FAIL - timed out')
398-
399-
400-
def test_run_python_pythonpath_extend():
401-
code = '''import os, sys ; print('\\n'.join(sys.path))'''
402-
output = run_python('', args=('-c', code), pythonpath_extend=('dira', 'dirb'))
403-
assert b'/dira\n' in output
404-
assert b'/dirb\n' in output
405-
406-
407394
@contextlib.contextmanager
408395
def dns_tcp_server(ip_to_give, request_count=1):
409396
state = [0] # request count storage writable by thread

tests/dagpool_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
@brief Test DAGPool class
66
"""
77

8-
from nose.tools import *
98
import eventlet
109
from eventlet.dagpool import DAGPool, Collision, PropagateError
1110
import six
1211
from contextlib import contextmanager
1312
import itertools
1413

1514

15+
def assert_equals(a, b):
16+
"""Backwards compatibility so we don't have to touch a bunch of tests."""
17+
assert a == b
18+
19+
20+
assert_equal = assert_equals
21+
22+
1623
# Not all versions of nose.tools.assert_raises() support the usage in this
1724
# module, but it's straightforward enough to code that explicitly.
1825
@contextmanager
@@ -375,7 +382,7 @@ def test_spawn_multiple():
375382
dict(a=1, b=2, c=3,
376383
d="dval", e="eval", f="fval", g="gval", h="hval"))
377384
assert_equals(pool.running(), 0)
378-
assert_false(pool.running_keys())
385+
assert not pool.running_keys()
379386
assert_equals(pool.waiting(), 0)
380387
assert_equals(pool.waiting_for("h"), set())
381388

tests/greenio_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import sys
1010
import tempfile
1111

12-
from nose.tools import eq_
13-
1412
import eventlet
1513
from eventlet import event, greenio, debug
1614
from eventlet.hubs import get_hub
@@ -39,7 +37,7 @@ def expect_socket_timeout(function, *args):
3937
raise AssertionError("socket.timeout not raised")
4038
except socket.timeout as e:
4139
assert hasattr(e, 'args')
42-
eq_(e.args[0], 'timed out')
40+
assert e.args[0] == 'timed out'
4341

4442

4543
def min_buf_size():
@@ -672,8 +670,8 @@ def test_datagram_socket_operations_work(self):
672670
sender.sendto(b'second', 0, address)
673671

674672
sender_address = ('127.0.0.1', sender.getsockname()[1])
675-
eq_(receiver.recvfrom(1024), (b'first', sender_address))
676-
eq_(receiver.recvfrom(1024), (b'second', sender_address))
673+
assert receiver.recvfrom(1024) == (b'first', sender_address)
674+
assert receiver.recvfrom(1024) == (b'second', sender_address)
677675

678676

679677
def test_get_fileno_of_a_socket_works():

tests/nosewrapper.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/pools_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_it(self):
245245
SOMETIMES = RuntimeError('I fail half the time')
246246

247247

248-
class TestTookTooLong(Exception):
248+
class TookTooLongToRunTest(Exception):
249249
pass
250250

251251

tests/test_infrastructure_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Tests for the testing infrastructure."""
2+
3+
from . import run_python
4+
5+
6+
def test_run_python_timeout():
7+
output = run_python('', args=('-c', 'import time; time.sleep(0.5)'), timeout=0.1)
8+
assert output.endswith(b'FAIL - timed out')
9+
10+
11+
def test_run_python_pythonpath_extend():
12+
code = '''import os, sys ; print('\\n'.join(sys.path))'''
13+
output = run_python('', args=('-c', code), pythonpath_extend=('dira', 'dirb'))
14+
assert b'/dira\n' in output
15+
assert b'/dirb\n' in output

0 commit comments

Comments
 (0)