Skip to content

Commit

Permalink
[QA] Adding --final-rss-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Feb 20, 2023
1 parent b8a51f5 commit 2d02ba3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# Ensuring there is no `generate=True` left remaining in calls to assert_pdf_equal:
grep -IRF generate=True test/ && exit 1
# Executing all tests:
pytest -vv
pytest -vv --final-rss-usage
- name: Uploading coverage report to codecov.io ☑
if: matrix.python-version == '3.10' && matrix.platform == 'ubuntu-latest'
run: bash <(curl -s https://codecov.io/bash)
Expand Down
1 change: 1 addition & 0 deletions docs/TextStyling.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pdf.output("markdown-styled.pdf")
Using other fonts means that their variants (bold, italics)
must be registered using `add_font` with `style="B"` and `style="I"`.
Several unit tests in `test/text/` demonstrate that:

* [test_cell_markdown_with_ttf_fonts](https://github.com/PyFPDF/fpdf2/blob/2.6.1/test/text/test_cell.py#L155)
* [test_multi_cell_markdown_with_ttf_fonts](https://github.com/PyFPDF/fpdf2/blob/2.6.1/test/text/test_multi_cell_markdown.py#L27)

Expand Down
20 changes: 19 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gc, linecache, tracemalloc
from subprocess import check_output, CalledProcessError, PIPE

from psutil import Process # transitive dependency of memunit
import pytest

from fpdf.template import Template
Expand Down Expand Up @@ -257,20 +258,37 @@ def handler(_, __):
# Enabling this check creates an increase in memory usage,
# so we require an opt-in through a CLI argument:
def pytest_addoption(parser):
parser.addoption(
"--final-rss-usage",
action="store_true",
help="At the end of the tests execution, display the current RSS memory usage",
)
parser.addoption(
"--trace-malloc",
action="store_true",
help="Trace main memory allocations differences during the whole execution",
)


@pytest.fixture(scope="session", autouse=True)
def final_rss_usage(request):
yield
if request.config.getoption("final_rss_usage"):
rss_in_mib = Process().memory_info().rss / 1024 / 1024
capmanager = request.config.pluginmanager.getplugin("capturemanager")
with capmanager.global_and_fixture_disabled():
print("\n")
print(f"[psutil] Final process RSS memory usage: {rss_in_mib:.1f} MiB")


@pytest.fixture(scope="session", autouse=True)
def trace_malloc(request):
if not request.config.getoption("trace_malloc"):
yield
return
capmanager = request.config.pluginmanager.getplugin("capturemanager")
gc.collect()
# Top-10 recipe from: https://docs.python.org/3/library/tracemalloc.html#display-the-top-10
tracemalloc.start()
snapshot1 = tracemalloc.take_snapshot().filter_traces(
(
Expand All @@ -288,6 +306,6 @@ def trace_malloc(request):
)
top_stats = snapshot2.compare_to(snapshot1, "lineno")
with capmanager.global_and_fixture_disabled():
print("[ Top 10 differences ]")
print("[tracemalloc] Top 10 differences:")
for stat in top_stats[:10]:
print(stat)

0 comments on commit 2d02ba3

Please sign in to comment.