File: test_with_profiling.py

package info (click to toggle)
rdiff-backup 2.2.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,640 kB
  • sloc: python: 24,129; javascript: 9,512; sh: 1,230; ansic: 580; makefile: 36
file content (21 lines) | stat: -rw-r--r-- 751 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import profile
import pstats
import os

# if you need to profile a certain test, replace the "metadatatest" placeholder
# with the test you want to profile and all functions will get imported into
# the current namespace.
# I didn't find a way to do it dynamically...
from metadatatest import *  # noqa: F403, F401 star import and unused

# Create a profile output filename (don't forget to adapt the name)
abs_work_dir = os.getenvb(
    b'TOX_ENV_DIR',
    os.getenvb(b'VIRTUAL_ENV', os.path.join(os.getcwdb(), b'build')))
profile_output = os.path.join(abs_work_dir, b"profile-metadatatest.out")

# Run and output the test profile
profile.run("unittest.main()", profile_output)
p = pstats.Stats(profile_output)
p.sort_stats('time')
p.print_stats(40)