def test_nested(self): """Test that nesting of type checker context managers works as expected.""" def foo(a: int): pass with TypeChecker(__name__), pytest.warns(TypeWarning) as record: foo('x') with TypeChecker(__name__): foo('x') assert len(record) == 3
def test_nested(self): """Test that nesting of type checker context managers works as expected.""" def foo(a: int): pass with warnings.catch_warnings(record=True): warnings.simplefilter('ignore', DeprecationWarning) parent = TypeChecker(__name__) child = TypeChecker(__name__) with parent, pytest.warns(TypeWarning) as record: foo('x') with child: foo('x') assert len(record) == 3
def checker(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) return TypeChecker(__name__)
def checker(self): return TypeChecker(__name__)
def init_typeguard() -> None: from typeguard import TypeChecker global tc tc = TypeChecker(check_mods) tc.start()
from __future__ import annotations import logging import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from pytest import fixture from sqlalchemy.exc import SQLAlchemyError from typeguard import TypeChecker from labster.app import create_app from labster.domain.services.constants import get_initial_constants from labster.extensions import db as _db checker = TypeChecker("labster") if "TYPECHECK" in os.environ: logging.captureWarnings(True) if not checker.active: checker.start() class TestConfig: TESTING = True CSRF_ENABLED = False MAIL_SENDER = "*****@*****.**" MAIL_SUPPRESS_SEND = True SECRET_KEY = "changeme" SERVER_NAME = "localhost.localdomain" SQLALCHEMY_DATABASE_URI = "sqlite://"
Supposed to replace the too-complex current UnitTest-based testing framework. DI and functions over complex inheritance hierarchies FTW! """ import logging import os import warnings import pytest from typeguard import TypeChecker pytest_plugins = ["abilian.testing.fixtures"] if os.environ.get("TYPECHECK"): checker = TypeChecker("abilian") logging.captureWarnings(True) if not checker.active: checker.start() if os.environ.get("FAIL_ON_WARNINGS"): # Don't remove ! # noinspection PyUnresolvedReferences import pandas warnings.simplefilter("error") if os.environ.get("COLLECT_ANNOTATIONS"): def pytest_collection_finish(session): """Handle the pytest collection finish hook: configure pyannotate.