Package: pytest-monitor
pytest-monitorPytest-monitor is a pytest plugin designed for analyzing resource usage.FeaturesAnalyze your resources consumption through test functions:memory consumptiontime durationCPU usageKeep a history of your resource consumption measurements.Compare how your code behaves between different environments.UsageSimply runpytestas usual:pytest-monitoris active by default as soon as it is installed.
After running your first session, a .pymonsqlitedatabase will be accessible in the directory where pytest was run.Example of information collected for the execution context:ENV_HCPU_COUNTCPU_FREQUENCY_MHZCPU_TYPECPU_VENDORRAM_TOTAL_MBMACHINE_NODEMACHINE_TYPEMACHINE_ARCHSYSTEM_INFOPYTHON_INFO8294b1326007d9f4c8a1680f9590c23d363000x86_64Intel(R) Xeon(R) Gold 6154 CPU @ 3.00GHz772249some.host.vm.frx86_6464bitLinux - 3.10.0-693.el7.x86_643.6.8 (default, Jun 28 2019, 11:09:04) n[GCC …Here is an example of collected data stored in the result database:RUN_DATEENV_HSCM_IDITEM_START_TIMEITEMKINDCOMPONENTTOTAL_TIMEUSER_TIMEKERNEL_TIMECPU_USAGEMEM_USAGE2020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:36.890477pkg1.test_mod1/test_sleep1functionNone1.0056690.540.060.5966181.7812502020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:39.912029pkg1.test_mod1/test_heavy[10-10]functionNone0.0296270.550.0821.2644981.7812502020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:39.948922pkg1.test_mod1/test_heavy[100-100]functionNone0.0282620.560.0922.9987731.7812502020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:39.983869pkg1.test_mod1/test_heavy[1000-1000]functionNone0.0301310.560.1021.9042772.1328122020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:40.020823pkg1.test_mod1/test_heavy[10000-10000]functionNone0.0600600.570.1411.82160141.2929692020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:40.093490pkg1.test_mod2/test_sleep_400msfunctionNone0.4048600.580.151.8030932.3203122020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:40.510525pkg2.test_mod_a/test_master_sleepfunctionNone5.0060395.570.151.1426202.3203122020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:45.530780pkg3.test_mod_cl/test_method1functionNone0.0305055.580.16188.1647622.3203122020-02-17T09:11:36.7312338294b1326007d9f4c8a1680f9590c23dde23e6bdb987ae21e84e6c7c0357488ee66f26392020-02-17T09:11:50.582954pkg4.test_mod_a/test_force_monitorfunctiontest1.00501511.570.1711.6814162.320312DocumentationA full documentation isavailable.InstallationYou can installpytest-monitorviaconda(through theconda-forgechannel):$ conda install pytest-monitor -c https://conda.anaconda.org/conda-forgeAnother possibility is to installpytest-monitorviapipfromPyPI:$ pip install pytest-monitorRequirementsYou will need a valid Python 3.5+ interpreter. To get measures, we rely on:psutilto extract CPU usagememory_profilerto collect memory usageandpytest(obviously!)Note: this plugin doesn’t work with unittestStorage backendsBy default, pytest-monitor stores its result in a local SQLite3 local database, making results accessible.
If you need a more powerful way to analyze your results, checkout themonitor-server-apiwhich brings both a REST Api for storing and historize your results and an API to query your data.
An alternative service (using MongoDB) can be used thanks to a contribution from @dremdem:pytest-monitor-backend.ContributingContributions are very welcome. Tests can be run withtox. Before submitting a pull request, please ensure
that:both internal tests and examples are passing.internal tests have been written if necessary.if your contribution provides a new feature, make sure to provide an example and update the documentation accordingly.LicenseThis code is distributed under theMITlicense.pytest-monitoris free, open-source software.IssuesIf you encounter any problem, pleasefile an issuealong with a detailed description.AuthorThe main author ofpytest-monitoris Jean-Sébastien Dieu, who can be reached atjdieu@salsify.fr.Thispytestplugin was generated withCookiecutteralong with@hackebrot’scookiecutter-pytest-plugintemplate.