From 31367d0a7abe9eb59767549e11fc467010d59f0a Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 24 Dec 2020 22:21:41 +0000 Subject: [PATCH] test:cleanup pytest config --- Makefile | 4 ++-- setup.cfg | 7 +++---- tests/conftest.py | 26 ++++++++++++++++++++++++++ tests/py37_asyncio.py | 1 - tests/tests_concurrent.py | 1 - tests/tests_contrib.py | 1 - tests/tests_itertools.py | 1 - tests/tests_keras.py | 1 - tests/tests_main.py | 1 - tests/tests_notebook.py | 1 - tests/tests_pandas.py | 1 - tests/tests_perf.py | 1 - tests/tests_synchronisation.py | 1 - tests/tests_tqdm.py | 25 +------------------------ tests/tests_version.py | 2 -- tox.ini | 4 ++-- 16 files changed, 34 insertions(+), 44 deletions(-) create mode 100644 tests/conftest.py diff --git a/Makefile b/Makefile index 82f239da..249e9b04 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ testperf: pytest -k tests_perf testtimer: - pytest --durations=10 + pytest # another performance test, to check evolution across commits testasv: @@ -116,7 +116,7 @@ pre-commit: # quick sanity checks @make --no-print-directory testsetup flake8 -j 8 --count --statistics setup.py .meta/ tqdm/ tests/ examples/ - pytest -qq -k "basic_overhead or not (perf or keras or pandas or monitoring)" + pytest -qq --durations=1 -k "basic_overhead or not (perf or keras or pandas or monitoring)" prebuildclean: @+python -c "import shutil; shutil.rmtree('build', True)" @+python -c "import shutil; shutil.rmtree('dist', True)" diff --git a/setup.cfg b/setup.cfg index ca9a73e7..7d32589d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,10 +16,9 @@ split_before_named_assigns=False split_before_closing_bracket=False [tool:pytest] -python_files = tests_*.py -testpaths = tests -addopts = -v --tb=short -usefixtures = pretest_posttest +python_files=tests_*.py +testpaths=tests +addopts=-v --tb=short -rxs --durations=0 --durations-min=0.1 [metadata] name = tqdm diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..da7d3ccd --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,26 @@ +import sys +from tqdm import tqdm +from pytest import fixture + + +@fixture(autouse=True) +def pretest_posttest(): + """Fixture for all tests ensuring environment cleanup""" + try: + sys.setswitchinterval(1) + except AttributeError: + sys.setcheckinterval(100) # deprecated + + if getattr(tqdm, "_instances", False): + n = len(tqdm._instances) + if n: + tqdm._instances.clear() + raise EnvironmentError( + "{0} `tqdm` instances still in existence PRE-test".format(n)) + yield + if getattr(tqdm, "_instances", False): + n = len(tqdm._instances) + if n: + tqdm._instances.clear() + raise EnvironmentError( + "{0} `tqdm` instances still in existence POST-test".format(n)) diff --git a/tests/py37_asyncio.py b/tests/py37_asyncio.py index b82eff6d..d76f5a6f 100644 --- a/tests/py37_asyncio.py +++ b/tests/py37_asyncio.py @@ -6,7 +6,6 @@ import asyncio from pytest import mark from tqdm.asyncio import tqdm_asyncio, tarange -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import StringIO, closing tqdm = partial(tqdm_asyncio, miniters=0, mininterval=0) diff --git a/tests/tests_concurrent.py b/tests/tests_concurrent.py index 3cac02e7..ebef677e 100644 --- a/tests/tests_concurrent.py +++ b/tests/tests_concurrent.py @@ -6,7 +6,6 @@ from warnings import catch_warnings from pytest import mark from tqdm.contrib.concurrent import thread_map, process_map -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, skip, StringIO, closing diff --git a/tests/tests_contrib.py b/tests/tests_contrib.py index 8b7e9fc0..eca3d18d 100644 --- a/tests/tests_contrib.py +++ b/tests/tests_contrib.py @@ -4,7 +4,6 @@ Tests for `tqdm.contrib`. import sys from tqdm.contrib import tenumerate, tzip, tmap -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, StringIO, closing diff --git a/tests/tests_itertools.py b/tests/tests_itertools.py index 32f23de9..ede9949d 100644 --- a/tests/tests_itertools.py +++ b/tests/tests_itertools.py @@ -4,7 +4,6 @@ Tests for `tqdm.contrib.itertools`. import itertools from tqdm.contrib.itertools import product -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import StringIO, closing diff --git a/tests/tests_keras.py b/tests/tests_keras.py index 62b4d1df..9d1b21e1 100644 --- a/tests/tests_keras.py +++ b/tests/tests_keras.py @@ -1,7 +1,6 @@ from __future__ import division from tqdm import tqdm -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, StringIO, closing diff --git a/tests/tests_main.py b/tests/tests_main.py index b348018d..990348d4 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -8,7 +8,6 @@ import subprocess from tqdm.cli import main, TqdmKeyError, TqdmTypeError from tqdm.utils import IS_WIN -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import skip, _range, closing, UnicodeIO, StringIO, BytesIO diff --git a/tests/tests_notebook.py b/tests/tests_notebook.py index c8e858b8..004d7e57 100644 --- a/tests/tests_notebook.py +++ b/tests/tests_notebook.py @@ -1,5 +1,4 @@ from tqdm.notebook import tqdm as tqdm_notebook -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import def test_notebook_disabled_description(): diff --git a/tests/tests_pandas.py b/tests/tests_pandas.py index 07647e6c..fa65f82f 100644 --- a/tests/tests_pandas.py +++ b/tests/tests_pandas.py @@ -1,5 +1,4 @@ from tqdm import tqdm -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, skip, StringIO, closing random = importorskip("numpy.random") diff --git a/tests/tests_perf.py b/tests/tests_perf.py index 1ef9ed10..684b3709 100644 --- a/tests/tests_perf.py +++ b/tests/tests_perf.py @@ -11,7 +11,6 @@ except ImportError: import sys from tqdm import tqdm, trange -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, skip, StringIO, closing, _range, \ patch_lock diff --git a/tests/tests_synchronisation.py b/tests/tests_synchronisation.py index d3eb32c3..d5f7bab0 100644 --- a/tests/tests_synchronisation.py +++ b/tests/tests_synchronisation.py @@ -6,7 +6,6 @@ import sys from tqdm import tqdm, trange, TMonitor from .tests_perf import retry_on_except -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import from .tests_tqdm import importorskip, skip, StringIO, closing, patch_lock diff --git a/tests/tests_tqdm.py b/tests/tests_tqdm.py index 91b65ade..02eab10d 100644 --- a/tests/tests_tqdm.py +++ b/tests/tests_tqdm.py @@ -9,7 +9,7 @@ import os from functools import wraps from contextlib import contextmanager from pytest import raises as assert_raises -from pytest import fixture, importorskip, skip +from pytest import importorskip, skip from warnings import catch_warnings, simplefilter from tqdm import tqdm @@ -118,29 +118,6 @@ def cpu_timify(t, timer=None): return timer -@fixture(autouse=True) -def pretest_posttest(): - """Fixture for all tests ensuring environment cleanup""" - try: - sys.setswitchinterval(1) - except AttributeError: - sys.setcheckinterval(100) # deprecated - - if getattr(tqdm, "_instances", False): - n = len(tqdm._instances) - if n: - tqdm._instances.clear() - raise EnvironmentError( - "{0} `tqdm` instances still in existence PRE-test".format(n)) - yield - if getattr(tqdm, "_instances", False): - n = len(tqdm._instances) - if n: - tqdm._instances.clear() - raise EnvironmentError( - "{0} `tqdm` instances still in existence POST-test".format(n)) - - class UnicodeIO(IOBase): """Unicode version of StringIO""" def __init__(self, *args, **kwargs): diff --git a/tests/tests_version.py b/tests/tests_version.py index 6783d386..3de482f8 100644 --- a/tests/tests_version.py +++ b/tests/tests_version.py @@ -2,8 +2,6 @@ from ast import literal_eval import re -from .tests_tqdm import pretest_posttest # NOQA, pylint: disable=unused-import - def test_version(): """Test version string""" diff --git a/tox.ini b/tox.ini index 7cc43c56..6232baf9 100644 --- a/tox.ini +++ b/tox.ini @@ -26,7 +26,7 @@ deps = {[coverage]deps} codecov commands = - pytest --durations=10 --cov=tqdm --cov-report=xml --cov-report=term -k "not tests_perf" + pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not tests_perf" - coveralls codecov - codacy report -r coverage.xml @@ -57,7 +57,7 @@ deps = {[extra]deps} [testenv:perf] deps = pytest -commands = pytest --durations=0 -k tests_perf +commands = pytest -k tests_perf [testenv:flake8] deps = flake8