Skip to content

Commit

Permalink
#40 - Force garbage collector to run between each tests
Browse files Browse the repository at this point in the history
  • Loading branch information
js-dieu committed Aug 23, 2021
1 parent f19f3b7 commit 3658492
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/sources/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

* :release:`1.6.1 <2021-08-23>`
* :bug:`#43` Fixes a bug that prevent sending session tags correctly.
* :bug:`#40` Force garbage collector to run between tests (better result accuracy)

* :release:`1.6.0 <2021-04-16>`
* :feature:`#0` Support for python 3.5
* :feature:`#35` Better support for Doctest item.
Expand Down
13 changes: 12 additions & 1 deletion docs/sources/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,15 @@ The following table explains how both fields are mapped:

Note that none of these two fields will be added if:
* the CI context is incomplete
* the CI context cannot be computed.
* the CI context cannot be computed.

Parameters affecting measures
-----------------------------
By default, pytest-monitor runs the garbage collector prior to execute the test function.
This leads to finer memory measurements. In the case where you want to disable this call to the
garbage collector, you just have to set the option `--no-gc` on the command line.

.. code-block:: shell
bash $> pytest --no-gc
2 changes: 1 addition & 1 deletion pytest_monitor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.6.0"
__version__ = "1.6.1"
__author__ = "Jean-Sebastien Dieu"
5 changes: 5 additions & 0 deletions pytest_monitor/pytest_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import gc
import memory_profiler
import pytest
import time
Expand Down Expand Up @@ -44,6 +45,8 @@ def pytest_addoption(parser):
group.addoption('--component-prefix', action='store', dest='mtr_component_prefix',
help='Prefix each found components with the given value (applies to all tests'
' run in this session).')
group.addoption('--no-gc', action="store_true", dest="mtr_no_gc",
help='Disable garbage collection between tests (may leads to non reliable measures)')
group.addoption('--description', action='store', default='', dest='mtr_description',
help='Use this option to provide a small summary about this run.')
group.addoption('--tag', action='append', dest='mtr_tags', default=[],
Expand Down Expand Up @@ -154,6 +157,8 @@ def prof():
if not PYTEST_MONITORING_ENABLED:
wrapped_function()
else:
if pyfuncitem.session.config.option.mtr_no_gc:
gc.collect()
prof()
return True

Expand Down

0 comments on commit 3658492

Please sign in to comment.