Closed MatthewFlamm closed 2 years ago
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.
@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()
@akaszynski indeed seems to work like a charm :tada:
I didn't realize that running doctest through pytest would already enable this functionality. This would reduce reliance on niche dependencies.
I originally tried this with gc.collect
and gave up. You had the idea of close_all
, which did the trick. Thanks for that.
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.Downsides
NUMBER
is not supported, butFLOAT_CMP
can be used.FLOAT_CMP
rounds to nearest whereasNUMBER
rounds down. Switching would prevent using normal doctest. This could potentially be avoided by using ELLIPSES instead, but it might have unintended edge cases.check_doctest_names