question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

doctest memory increasing

See original GitHub issue

Describe what maintenance you would like added.

The current usage of doctest has increasing memory. #2496 has increased the number of doctests to the point that the CI runs out of memory. Locally, the memory increases >10 GB on some commit refs. Currently, none of the Plotters are being closed, and thus memory increases each time a plot is made. Confirmation of this is below. However, normal doctest does not allow for convenient use of teardown code. And we’d have to add pyvista.all_close() to every doctest.

pytest-doctestplus can fix this issue while providing more flexible doctesting for our uses. It allows using pytest fixtures, which enables for clean teardown code to be run after each doctest without adding fluff to each doctest.

When using pytest-doctestplus with the fixture below eliminates the memory buildup seen, which confirms that the plotters aren’t closing properly today.

@pytest.fixture(autouse=True)
def autoclose_plotters():
    yield
    pyvista.close_all()

Downsides

  • Potentially breaks usage with base doctest. The option flag NUMBER is not supported, but FLOAT_CMP can be used. FLOAT_CMP rounds to nearest whereas NUMBER rounds down. Switching would prevent using normal doctest. This could potentially be avoided by using ELLIPSES instead, but it might have unintended edge cases.
  • I’m not sure if this impacts check_doctest_names

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
akaszynskicommented, Apr 25, 2022

@MatthewFlamm, I’m finding this works on my end without using pytest-doctestplus

import pyvista

import pytest

@pytest.fixture(autouse=True)
def autoclose_plotters():
    yield
    pyvista.close_all()
1reaction
adeakcommented, Apr 25, 2022

I’m not sure if this impacts check_doctest_names

check_doctest_names only uses stdlib doctest as a parser, and it only checks for exceptions being raised in doctests (with the assumption that proper doctesting checks validity of results). So it should be of no concern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Doctest memory limit - Google Groups
The default memory limit exists for precisely one doctest (which ... In the past, whenever we've hit the limit, we've just increased the...
Read more >
Python Friday #69: Dynamic Output and Doctest
After last week's introduction to doctest it is now time to have a ... like with the date of a log message or...
Read more >
Python's doctest: Document and Test Your Code at Once
Such names improve your code's readability and maintainability. ... make your doctest test fail because the memory address will never match:.
Read more >
memory leak unit test c++ - Stack Overflow
Boost.Test will automatically tell you at the end of a test run if any of your unit tests leaked memory. I don't know...
Read more >
Better Ways to Test with doctest – the Fastest C++ Unit Testing ...
doctest is a relatively new C++ testing framework but is by far the fastest both in terms of compile times (by orders of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found