Skip to content

Commit e737722

Browse files
authored
Merge pull request #1420 from zm711/neo-no-tests
Testing: Skip network-dependent tests if no network access
2 parents 14d66a6 + 632615c commit e737722

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

doc/source/contributing.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,28 @@ The first time this is run, all of the Neo test files will be downloaded to your
208208
so the run time can be an hour or more.
209209
For subsequent runs, the files are already there, so the tests will run much faster.
210210

211+
Because Neo downloads datasets this can lead to issues in the course of offline development or
212+
for packaging Neo (e.g. for a Linux distribution). In order to not download datasets and to skip
213+
tests which require downloaded datasets the environment variable :code:`NEO_TESTS_NO_NETWORK` can
214+
be set to any truthy value (e.g. :code:`'True'``).
215+
216+
For macOS/Linux this can be done by doing:
217+
218+
.. code-block:: bash
219+
220+
NEO_TESTS_NO_NETWORK='True' pytest .
221+
222+
For Windows this can be done by doing:
223+
224+
.. code-block:: bat
225+
226+
set NEO_TESTS_NO_NETWORK=true
227+
228+
pytest .
229+
230+
This can also be done with a conda environment variable if developing in a conda env. To configure these
231+
see the docs at `conda env vars documentation`_.
232+
211233
It is often helpful to run only parts of the test suite. To test only the :mod:`neo.core` module,
212234
which is much quicker than testing :mod:`neo.io`, run::
213235

@@ -465,4 +487,5 @@ Making a release
465487
.. _PyPI: https://pypi.org/project/neo
466488
.. _`continuous integration server`: https://github.com/NeuralEnsemble/python-neo/actions
467489
.. _`Read the Docs`: https://neo.readthedocs.io/en/latest/
468-
.. _`docs configuration page`: https://readthedocs.org/projects/neo/
490+
.. _`docs configuration page`: https://readthedocs.org/projects/neo/
491+
.. _`conda env vars documentation`: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment

neo/test/iotest/common_io_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def setUpClass(cls, *args, **kwargs):
115115
cls.io_readandwrite = list(set(cls.ioclass.readable_objects) & set(cls.ioclass.writeable_objects))
116116
# these objects can be either written or read
117117
cls.io_readorwrite = list(set(cls.ioclass.readable_objects) | set(cls.ioclass.writeable_objects))
118-
if HAVE_DATALAD:
118+
if HAVE_DATALAD and can_use_network():
119119
for remote_path in cls.entities_to_download:
120120
download_dataset(repo=repo_for_test, remote_path=remote_path)
121121

neo/test/rawiotest/common_rawio_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def setUp(self):
6565
"""
6666
self.shortname = self.rawioclass.__name__.lower().replace("rawio", "")
6767

68-
if HAVE_DATALAD:
68+
if HAVE_DATALAD and self.use_network:
6969
for remote_path in self.entities_to_download:
7070
download_dataset(repo=repo_for_test, remote_path=remote_path)
7171
else:

neo/test/rawiotest/tools.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ def can_use_network():
1212
"""
1313
Return True if network access is allowed
1414
"""
15+
16+
if os.environ.get("NEO_TESTS_NO_NETWORK", False):
17+
return False
1518
try:
1619
import datalad
17-
1820
HAVE_DATALAD = True
1921
except:
2022
HAVE_DATALAD = False
2123
if not HAVE_DATALAD:
2224
return False
23-
if os.environ.get("NOSETESTS_NO_NETWORK", False):
24-
return False
25-
if os.environ.get("TRAVIS") == "true":
26-
return False
2725
return True

neo/test/utils/test_datasets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import unittest
2-
2+
import pytest
33
from neo.utils.datasets import download_dataset, default_testing_repo
4+
from neo.test.rawiotest.tools import can_use_network
45

56

7+
@pytest.mark.skipif(not can_use_network(), reason="Must have acess to network to run test")
68
class TestDownloadDataset(unittest.TestCase):
79
def test_download_dataset(self):
810
local_path = download_dataset(repo=default_testing_repo, remote_path="blackrock/blackrock_2_1")

0 commit comments

Comments
 (0)