pytest-antilru 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru/__init__.py +0 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru/__pycache__/__init__.cpython-36.pyc +0 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru/__pycache__/main.cpython-36.pyc +0 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru/main.py +59 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/PKG-INFO +24 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/SOURCES.txt +11 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/dependency_links.txt +1 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/entry_points.txt +3 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/requires.txt +1 -0
- home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru-0.2.0-py3.6.egg-info/top_level.txt +1 -0
home/ipwnponies/repos/pytest-antilru/venv/lib/python3.6/site-packages/pytest_antilru/__init__.py
ADDED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Please don't use this, it's inconsistent and will be monkey-patched left and right.
|
|
2
|
+
# We're only importing it to update functools module's reference
|
|
3
|
+
import functools
|
|
4
|
+
import sys
|
|
5
|
+
from functools import wraps # pylint: disable=ungrouped-imports
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
if not hasattr(functools, 'lru_cache'):
|
|
10
|
+
# Several py2 backport packages
|
|
11
|
+
try:
|
|
12
|
+
import backports.functools_lru_cache as functools
|
|
13
|
+
except ImportError:
|
|
14
|
+
# functools32 py2 backport
|
|
15
|
+
try:
|
|
16
|
+
import functools32 as functools
|
|
17
|
+
except ImportError:
|
|
18
|
+
sys.exit('Cannot use pytest-antilru, no lru_cache installed!')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
CACHED_FUNCTIONS = []
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.hookimpl(hookwrapper=True)
|
|
25
|
+
def pytest_collection(session): # pylint: disable=unused-argument
|
|
26
|
+
"""Monkey patch lru_cache, before any module imports occure."""
|
|
27
|
+
|
|
28
|
+
# Gotta hold on to this before we patch it away
|
|
29
|
+
old_lru_cache = functools.lru_cache
|
|
30
|
+
|
|
31
|
+
@wraps(functools.lru_cache)
|
|
32
|
+
def lru_cache_wrapper(*args, **kwargs): # type: ignore
|
|
33
|
+
"""Wrap lru_cache decorator, to track which functions are decorated."""
|
|
34
|
+
|
|
35
|
+
# Apply lru_cache params (maxsize, typed)
|
|
36
|
+
decorated_function = old_lru_cache(*args, **kwargs)
|
|
37
|
+
|
|
38
|
+
# Mimicking lru_cache: https://github.com/python/cpython/blob/v3.7.2/Lib/functools.py#L476-L478
|
|
39
|
+
@wraps(decorated_function)
|
|
40
|
+
def decorating_function(user_function): # type: ignore
|
|
41
|
+
"""Wraps the user function, which is what everyone is actually using. Including us."""
|
|
42
|
+
wrapper = decorated_function(user_function)
|
|
43
|
+
CACHED_FUNCTIONS.append(wrapper)
|
|
44
|
+
return wrapper
|
|
45
|
+
|
|
46
|
+
return decorating_function
|
|
47
|
+
|
|
48
|
+
# Monkey patch the wrapped lru_cache decorator
|
|
49
|
+
functools.lru_cache = lru_cache_wrapper # type: ignore
|
|
50
|
+
yield
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.hookimpl(hookwrapper=True)
|
|
54
|
+
def pytest_runtest_teardown(item, nextitem): # pylint: disable=unused-argument
|
|
55
|
+
"""Call cache_clear on every cache_function, after every test run."""
|
|
56
|
+
for function in CACHED_FUNCTIONS:
|
|
57
|
+
function.cache_clear()
|
|
58
|
+
|
|
59
|
+
yield
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: pytest-antilru
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Bust functools.lru_cache when running pytest to avoid test pollution
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: UNKNOWN
|
|
7
|
+
Author-email: UNKNOWN
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Description: Caching with functools.lru_cache is great for performance. It works so well that it'll even
|
|
10
|
+
speed up your unit test runs. All you need to sacrifice in return is test isolation and your sanity.
|
|
11
|
+
|
|
12
|
+
Imagine, you mock some things out and a function caches those results. On your next test run, it doesn't matter what you
|
|
13
|
+
mock, the results are already cached. Now trying running those two test out-of-order sequence and tell me how it goes.
|
|
14
|
+
|
|
15
|
+
Platform: UNKNOWN
|
|
16
|
+
Classifier: Development Status :: 4 - Beta
|
|
17
|
+
Classifier: Framework :: Pytest
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 2
|
|
20
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.cfg
|
|
3
|
+
setup.py
|
|
4
|
+
pytest_antilru/__init__.py
|
|
5
|
+
pytest_antilru/main.py
|
|
6
|
+
pytest_antilru.egg-info/PKG-INFO
|
|
7
|
+
pytest_antilru.egg-info/SOURCES.txt
|
|
8
|
+
pytest_antilru.egg-info/dependency_links.txt
|
|
9
|
+
pytest_antilru.egg-info/entry_points.txt
|
|
10
|
+
pytest_antilru.egg-info/requires.txt
|
|
11
|
+
pytest_antilru.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest_antilru
|