From 4f3ccf213d813bb57775b2643b8bae5e08cbbbd0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 3 Jan 2023 15:21:15 -0500 Subject: refactor: a better way to have maybe-importable third-party modules --- tests/helpers.py | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'tests/helpers.py') diff --git a/tests/helpers.py b/tests/helpers.py index 1645138c..0503097e 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -15,12 +15,10 @@ import subprocess import textwrap import warnings -from types import ModuleType from typing import ( cast, Any, Callable, Generator, Iterable, List, Optional, Set, Tuple, Type, Union, ) -from unittest import mock import pytest @@ -284,24 +282,6 @@ def change_dir(new_dir: str) -> Generator[None, None, None]: os.chdir(old_dir) -def without_module(using_module: ModuleType, missing_module_name: str) -> mock._patch[Any]: - """ - Hide a module for testing. - - Use this in a test function to make an optional module unavailable during - the test:: - - with without_module(product.something, 'tomli'): - use_toml_somehow() - - Arguments: - using_module: a module in which to hide `missing_module_name`. - missing_module_name (str): the name of the module to hide. - - """ - return mock.patch.object(using_module, missing_module_name, None) - - def assert_count_equal(a: Iterable[Union[int, str]], b: Iterable[Union[int, str]]) -> None: """ A pytest-friendly implementation of assertCountEqual. -- cgit v1.2.1