From 63ceb3087a1080154f477da528326f7aa13f388c Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Tue, 22 Oct 2024 11:15:39 -0500 Subject: [PATCH 1/2] track memory usage in pytest --- .github/workflows/ci.yaml | 1 + test/conftest.py | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/conftest.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c2f462aaa..35c818461 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,6 +101,7 @@ jobs: MINIFORGE_INSTALL_DIR=.miniforge3 . "$MINIFORGE_INSTALL_DIR/bin/activate" testing cd test + export PYTEST_ADDOPTS="-v" python -m pip install pytest python -m pytest --cov=mirgecom --durations=0 --tb=native --junitxml=pytest.xml --doctest-modules -rxsw . ../doc/*.rst ../doc/*/*.rst diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 000000000..20170b5db --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,58 @@ +"""Common functions for all tests.""" + +__copyright__ = """ +Copyright (C) 2024 University of Illinois Board of Trustees +""" + +__license__ = """ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" + +import pytest + + +@pytest.fixture(autouse=True) +def mem_usage(capsys, pytestconfig): + # Code that will run before your test goes here + + yield + + # Code that will run after your test goes here + + # {{{ Memory usage reporting + + if not pytestconfig.option.verbose: + return + + # Copied from logpyle.MemoryHwm + import os + if os.uname().sysname == "Linux": + fac = 1024 + elif os.uname().sysname == "Darwin": + fac = 1024*1024 + else: + fac = 0 + + from resource import RUSAGE_SELF, getrusage + res = getrusage(RUSAGE_SELF) + + with capsys.disabled(): + print(f" HWM={res.ru_maxrss / fac}") + + # }}} From ce3adb3d0f3479f7fba10ed0a946bab38470377a Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Thu, 24 Oct 2024 13:44:37 -0500 Subject: [PATCH 2/2] Disable coverage --- .github/workflows/ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 35c818461..edaa07fde 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,9 +101,8 @@ jobs: MINIFORGE_INSTALL_DIR=.miniforge3 . "$MINIFORGE_INSTALL_DIR/bin/activate" testing cd test - export PYTEST_ADDOPTS="-v" python -m pip install pytest - python -m pytest --cov=mirgecom --durations=0 --tb=native --junitxml=pytest.xml --doctest-modules -rxsw . ../doc/*.rst ../doc/*/*.rst + python -m pytest --durations=0 --tb=native --junitxml=pytest.xml --doctest-modules -rxsw . ../doc/*.rst ../doc/*/*.rst examples: name: Examples