Skip to content

support pypy - add gc.collect() #2

Description

@mattip

Thanks for this code

PyPy requires forcing a collection before measuring memory usage after a test. For me it was enough to modify the runtest code:

is_pypy = '__pypy__' in sys.builtin_module_names

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
    if configuration.getoption('memory_usage') or configuration.getini('memory_usage'):
        if not is_pypy:
            gc.disable()
        state.before_call = get_memory(state.process)
        yield
        if is_pypy:
            gc.collect();
        state.after_call = get_memory(state.process)
        if not is_pypy:
            gc.enable()
    else:
        yield

would you rather get this as a pull request?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions