summaryrefslogtreecommitdiff
path: root/changelog
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-08-21 17:27:06 +0300
committerRan Benita <ran@unusedvar.com>2020-08-26 17:43:57 +0300
commit98891a59479e3de6fe4cabc770aaad894211822a (patch)
tree96b3e741a1c7b89e68812f6f01e41dcc6ac19130 /changelog
parent8730a7bb14cc0d14900e8149e13dfe83b4fd9a30 (diff)
downloadpytest-98891a59479e3de6fe4cabc770aaad894211822a.tar.gz
python: skip pytest_pycollect_makeitem work on certain names
When a Python object (module/class/instance) is collected, for each name in `obj.__dict__` (and up its MRO) the pytest_pycollect_makeitem hook is called for potentially creating a node for it. These Python objects have a bunch of builtin attributes that are extremely unlikely to be collected. But due to their pervasiveness, dispatching the hook for them ends up being mildly expensive and also pollutes PYTEST_DEBUG=1 output and such. Let's just ignore these attributes. On the pandas test suite commit 04e9e0afd476b1b8bed930e47bf60e, collect only, irrelevant lines snipped, about 5% improvement: Before: ``` 51195095 function calls (48844352 primitive calls) in 39.089 seconds ncalls tottime percall cumtime percall filename:lineno(function) 226602/54 0.145 0.000 38.940 0.721 manager.py:90(_hookexec) 72227 0.285 0.000 20.146 0.000 python.py:424(_makeitem) 72227 0.171 0.000 16.678 0.000 python.py:218(pytest_pycollect_makeitem) ``` After: ``` 48410921 function calls (46240870 primitive calls) in 36.950 seconds ncalls tottime percall cumtime percall filename:lineno(function) 181429/54 0.113 0.000 36.777 0.681 manager.py:90(_hookexec) 27054 0.130 0.000 17.755 0.001 python.py:465(_makeitem) 27054 0.121 0.000 16.219 0.001 python.py:218(pytest_pycollect_makeitem) ```
Diffstat (limited to 'changelog')
-rw-r--r--changelog/7671.trivial.rst6
1 files changed, 6 insertions, 0 deletions
diff --git a/changelog/7671.trivial.rst b/changelog/7671.trivial.rst
new file mode 100644
index 000000000..6dddf4cf0
--- /dev/null
+++ b/changelog/7671.trivial.rst
@@ -0,0 +1,6 @@
+When collecting tests, pytest finds test classes and functions by examining the
+attributes of python objects (modules, classes and instances). To speed up this
+process, pytest now ignores builtin attributes (like ``__class__``,
+``__delattr__`` and ``__new__``) without consulting the ``python_classes`` and
+``python_functions`` configuration options and without passing them to plugins
+using the ``pytest_pycollect_makeitem`` hook.