tqdm/tests/conftest.py

42 lines
1.0 KiB
Python
Raw Permalink 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()
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))
2021-01-04 01:58:06 +00:00
if sys.version_info[0] > 2:
@fixture
def capsysbin(capsysbinary):
2021-01-04 02:35:03 +00:00
"""alias for capsysbinary (py3)"""
2021-01-04 01:58:06 +00:00
return capsysbinary
else:
@fixture
def capsysbin(capsys):
2021-01-04 02:35:03 +00:00
"""alias for capsys (py2)"""
2021-01-04 01:58:06 +00:00
return capsys