From 841090491a74122e0ad25f66de129964dc6e17fe Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 3 Jan 2021 22:02:40 +0000 Subject: [PATCH] tests: warnings and timeout --- environment.yml | 1 + setup.cfg | 4 +++- tests/tests_concurrent.py | 11 +++++------ tests/tests_keras.py | 3 +++ tox.ini | 7 +++++-- tqdm/std.py | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/environment.yml b/environment.yml index 2ead4b1f..ebe42d84 100644 --- a/environment.yml +++ b/environment.yml @@ -17,6 +17,7 @@ dependencies: # tests (native) - pytest - pytest-cov +- pytest-timeout - pytest-asyncio # [py>=3.7] - flake8 - coverage diff --git a/setup.cfg b/setup.cfg index 65072d01..518cd363 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,9 +16,11 @@ split_before_named_assigns=False split_before_closing_bracket=False [tool:pytest] +timeout=30 +log_level=INFO python_files=tests_*.py testpaths=tests -addopts=-v --tb=short -rxs --durations=0 --durations-min=0.1 +addopts=-v --tb=short -rxs -W=error --durations=0 --durations-min=0.1 [metadata] name = tqdm diff --git a/tests/tests_concurrent.py b/tests/tests_concurrent.py index ebef677e..263c7ec6 100644 --- a/tests/tests_concurrent.py +++ b/tests/tests_concurrent.py @@ -1,12 +1,10 @@ """ Tests for `tqdm.contrib.concurrent`. """ -from warnings import catch_warnings - -from pytest import mark +from pytest import mark, warns from tqdm.contrib.concurrent import thread_map, process_map -from .tests_tqdm import importorskip, skip, StringIO, closing +from .tests_tqdm import importorskip, skip, StringIO, closing, TqdmWarning def incr(x): @@ -44,6 +42,7 @@ def test_chunksize_warning(iterables, should_warn): """Test contrib.concurrent.process_map chunksize warnings""" patch = importorskip("unittest.mock").patch with patch('tqdm.contrib.concurrent._executor_map'): - with catch_warnings(record=True) as w: + if should_warn: + warns(TqdmWarning, process_map, incr, *iterables) + else: process_map(incr, *iterables) - assert should_warn == bool(w) diff --git a/tests/tests_keras.py b/tests/tests_keras.py index 9d1b21e1..ca03de2b 100644 --- a/tests/tests_keras.py +++ b/tests/tests_keras.py @@ -1,9 +1,12 @@ from __future__ import division +from pytest import mark + from tqdm import tqdm from .tests_tqdm import importorskip, StringIO, closing +@mark.filterwarnings("ignore:.*:DeprecationWarning") def test_keras(): """Test tqdm.keras.TqdmCallback""" TqdmCallback = importorskip("tqdm.keras").TqdmCallback diff --git a/tox.ini b/tox.ini index 31f8b7df..7e5744f4 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ commands= deps = pytest pytest-cov + pytest-timeout py{37,38,39}: pytest-asyncio coverage coveralls @@ -41,7 +42,7 @@ allowlist_externals = {[extra]allowlist_externals} [testenv:py{27,py2}{,-tf}{,-keras}] commands = - pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not tests_perf" -o addopts= -v --tb=short -rxs --durations=10 + pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not tests_perf" -o addopts= -v --tb=short -rxs -W=error --durations=10 {[coverage]commands} # no cython/numpy/pandas @@ -49,7 +50,9 @@ commands = deps = {[extra]deps} [testenv:perf] -deps = pytest +deps = + pytest + pytest-timeout commands = pytest -k tests_perf [testenv:flake8] diff --git a/tqdm/std.py b/tqdm/std.py index b6567dc5..e0f231b3 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -712,7 +712,7 @@ class tqdm(Comparable): from pandas.core.window.rolling import Rolling from pandas.core.window.expanding import Expanding _Rolling_and_Expanding = Rolling, Expanding - except ImportError: + except ImportError: # pragma: no cover _Rolling_and_Expanding = None try: # pandas>=0.25.0 from pandas.core.groupby.generic import DataFrameGroupBy, \