pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Memory usage increases rapidly as the number of tests grows

Open Lucas-C opened this issue 2 years ago • 5 comments

Hi !

I am witnessing this memory usage increase on fpdf2, using memunit: https://github.com/PyFPDF/fpdf2/issues/641 A contributor also mentioned that it was reported on StackOverflow some years ago: https://stackoverflow.com/questions/20900380/py-test-excessive-memory-usage-with-large-number-of-tests

In short: for a tests suite with ~1000 unit tests, I have witnessed an increase in memory usage of more than 10MB for 40 unit tests added.

Is this surprising to you, or expected?

And secondly, could there be optimizations to make, in pytest or in my tests suite, in order to lower this memory usage?

I have searched the issues & discussions history about this but found nothing anwering those questions:

  • https://github.com/pytest-dev/pytest/issues?q=memory+leak
  • https://github.com/pytest-dev/pytest/discussions?discussions_q=memory+usage

Lucas-C avatar Dec 22 '22 16:12 Lucas-C

I wonder how much this changes with the -s flag or disabling the logging plugin

RonnyPfannschmidt avatar Dec 22 '22 17:12 RonnyPfannschmidt

I wonder how much this changes with the -s flag or disabling the logging plugin

On my computer, measures were similar when using -s or -p no:logging, no big difference.

Lucas-C avatar Dec 22 '22 18:12 Lucas-C

Is this surprising to you, or expected?

Definitely something is fishy, we routinely have thousands of tests in our suites at work, and we don't see a memory growth like that.

nicoddemus avatar Dec 23 '22 12:12 nicoddemus

Nope

More than 100k tests is a entirely different league than this

RonnyPfannschmidt avatar Mar 28 '25 10:03 RonnyPfannschmidt