Skip to content

No prompt running memory profiler against pytest #355

Open

Description

@hectorcanto

I'm trying to run memory_profiler against pytest but no prompt or logging is shown (while it does record a dat file for the plot).

I tried:

python -m memory_profiler pytest
mprof run pytest 
mprof run python -m pytest
pytest

with @profile, with pytest -s to avoid prompt capture or

fp = open('memory_profiler.log', 'w+')

@profile(stream=fp)

I added the decorator, either in a single test or in a function being used by that single test.

Relevant information:

  • python 3.8.9
  • pytest 6.2.5
  • memory-profile 0.60.0
  • inside a virtualenv

Any suggestions?
Thanks for any help

Activity

  1. changed the title [-]No prompt running memory profiler agains pytest[/-] [+]No prompt running memory profiler against pytest[/+] on Mar 21, 2022
  2. hackermandh commented on Dec 12, 2024

    @hackermandh

    OH, IT WORKS!

    To test a single test:

    Add from memory_profiler import profile to your test file, and @profile to your to-test function.

    Then you can use this to test this one file and get output:

    Can't share code because it's proprietary, but here's the output:

    image

    python -m memory_profiler pytest -sk test_my_code


    BTW, mprof run pytest creates a .dat file, and mprof plot --output file.png actually generates a file you can view. You can also use .svg instead of .png

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions