Skip to content

Commit 920431b

Browse files
committed
TST: use pytest, instead of nose
for compatibility with Python 3.10. The package `nose` is not compatible with Python 3.10, because it imports abstract base classes from the module `collections`, [`nose == 1.3.7`](https://pypi.org/project/nose/1.3.7/#history) imports in Python 3.10 without error, but `nosetests` fails, due to imports from the module `collections` of classes that have moved to the module `collections.abc`. The error raised contains: ``` File ".../.virtualenvs/.../lib/python3.10/site-packages/nose/suite.py", line 106, in _set_tests if isinstance(tests, collections.Callable) and not is_suite: AttributeError: module 'collections' has no attribute 'Callable' ``` Relevant information about CPython changes in `collections` (removal of ABCs): - python/cpython#23754 - https://bugs.python.org/issue37324 - https://docs.python.org/3.10/library/collections.abc.html#collections-abstract-base-classes - Deprecation since Python 3.3, present until Python 3.9: https://docs.python.org/3.9/library/collections.html#module-collections - Removed in Python 3.10: https://docs.python.org/3.10/whatsnew/3.10.html#removed The script `run_tests.py` is rewritten, based on `pytest` functionality. The file `test/transys_mathset_test.py` has been changed to mode 100644 in order to not need an equivalent `pytest` option for option `--exe` of `nose`. In the test script `tests/mathfunc_test.py`, the function `_get_state_input_output_pair_test` has been renamed to `_get_state_input_pair` to avoid its name being matched by the pattern `python_functions = test_* *_test` defined in the configuration file `tests/pytest.ini`.
1 parent f38f0f0 commit 920431b

30 files changed

Lines changed: 456 additions & 376 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tulip/_version.py
2+
.pytest_cache/
23
htmlcov/
34
*~
45
*.log

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install:
3737
- pip install dist/tulip-*.tar.gz
3838

3939
before_script:
40-
- pip install nose
40+
- pip install pytest
4141
- dot -V
4242

4343
script:

‎MANIFEST.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
recursive-include examples *.py README
22
include run_tests.py
33
include tests/*.py
4+
include tests/pytest.ini
45
include README.rst
56
include LICENSE
67
include doc/*

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ may also read API documentation using the standard pydoc tool. E.g., ::
6060
Testing
6161
-------
6262

63-
Tests are performed using `nose <http://readthedocs.org/docs/nose/>`_. From the
63+
Tests are performed using `pytest <https://pytest.org>`_. From the
6464
root of the source tree (i.e., where ``setup.py`` is located), ::
6565

6666
./run_tests.py

‎contrib/Vagrantfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
install_dependencies = <<-SHELL
1919
#!/bin/sh -e
2020
sudo apt-get -y update
21-
sudo apt-get -y install python-pip python-nose
21+
sudo apt-get -y install python-pip python-pytest
2222
sudo apt-get -y install python-numpy python-networkx python-scipy python-ply python-matplotlib
2323
sudo apt-get -y install python-pydot
2424
sudo apt-get -y install libglpk-dev

‎contrib/test_spin2dstar.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"""
77

88
import sys
9-
import nose
109

10+
import pytest
1111
from spin2dstar import spin_to_dstar
1212

1313

@@ -29,5 +29,4 @@ def test_spin_to_dstar():
2929

3030

3131
if __name__ == "__main__":
32-
sys.argv.append("--verbose")
33-
nose.run()
32+
pytest.main(['--verbose'])

‎doc/dev_guide.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ tests and any tests that should pass given a successful ``pip install tulip[hybr
8888
namely, when the optional packages ``cvxopt`` and ``polytope`` are present.
8989

9090
Provided the ``-f`` or ``--testfiles`` switch, it searches under the directory
91-
``tests/`` for files with names ending in "_test.py", and passes these to `nose
92-
<http://readthedocs.org/docs/nose/>`_. Use the flag "-h" to see driver script
93-
options. Extra details about options:
91+
``tests/`` for files with names ending in "_test.py", and passes these to
92+
`pytest <https://pytest.org>`_. Use the flag "-h" to
93+
see driver script options. Extra details about options:
9494

9595
* The flag "--cover" to generate a coverage report, which will likely be placed
9696
under ``tests/cover/``. It uses `Ned Batchelder's coverage module

0 commit comments

Comments
 (0)