diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-18 18:08:56 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-18 18:23:27 -0500 |
commit | a09b1714c26cde1542044f44295600679d4368fc (patch) | |
tree | b0330905216c5a80f6c5c675494a95a00b3997a2 /tests/helpers.py | |
parent | 94239ad30e56f8f4bf01dcaf8700cdecca86e7f1 (diff) | |
download | python-coveragepy-git-a09b1714c26cde1542044f44295600679d4368fc.tar.gz |
Simplify the testing of the toml extra, fixing #1084
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 9c6a0ad8..0621d7a9 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -10,6 +10,7 @@ import shutil import subprocess import sys +import mock from unittest_mixins import ModuleCleaner from coverage import env @@ -203,3 +204,21 @@ def arcs_to_arcz_repr(arcs): line += _arcs_to_arcz_repr_one(b) repr_list.append(line) return "\n".join(repr_list) + "\n" + + +def without_module(using_module, missing_module_name): + """ + 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, 'toml'): + 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) |