tqdm/tests/conftest.py

28 lines
757 B
Python
Raw Normal View History

2020-12-25 02:19:27 +00:00
"""Shared pytest config."""
2020-12-24 22:21:41 +00:00
import sys
2021-01-09 17:00:18 +00:00
2020-12-24 22:21:41 +00:00
from pytest import fixture
2021-01-09 17:00:18 +00:00
from tqdm import tqdm
2020-12-24 22:21:41 +00:00
@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()
2023-03-03 16:32:58 +00:00
raise EnvironmentError(f"{n} `tqdm` instances still in existence PRE-test")
2020-12-24 22:21:41 +00:00
yield
if getattr(tqdm, "_instances", False):
n = len(tqdm._instances)
if n:
tqdm._instances.clear()
2023-03-03 16:32:58 +00:00
raise EnvironmentError(f"{n} `tqdm` instances still in existence POST-test")