[pytest-dev] Garbage collection and pytest fixtures

Dan Nealschneider dan.nealschneider at gmail.com
Sat Oct 7 16:32:55 EDT 2017


Hey all-
I've been exploring some of our tests that use a lot of memory, and whose
memory use seems to grow over the course of a test run. In my preliminary
investiagtion it seems like some of the memory use can be attributed to
fixtures which create large objects. I'm using py.test 3.1.3 in python
2.7.13.

We have a bunch of conftests and a local pytest plugin that changes some
behaviors, so I want to check in about intended behavior before I go
further.

If I have a fixture like the following, should I expect the object returned
by the fixture to be garbage collected after the tests that use it complete?
Or after all the tests in the module complete? Or after the seesion
completes?

    @pytest.fixture(scope='module')
    def big_item():
        return [0] *1000000

Is this a reasonable way to use a fixture, or is there a better way to
reuse a large and
expensive-to-create item across tests?

Thanks,
Dan N
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20171007/4db42dab/attachment.html>


More information about the pytest-dev mailing list