Skip to content

Commit

Permalink
Added test to make sure things work with sub-processes
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Dec 2, 2016
1 parent f1b4b26 commit b4cb315
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion psrecord/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,32 @@
import sys
import subprocess

from ..main import main, monitor
import psutil
from ..main import main, monitor, all_children

TEST_CODE = """
import subprocess
p = subprocess.Popen('sleep 5'.split())
p.wait()
"""


def test_all_children(tmpdir):

filename = tmpdir.join('test.py').strpath

with open(filename, 'w') as f:
f.write(TEST_CODE)

p = subprocess.Popen('{0} {1}'.format(sys.executable, filename).split())

import time
time.sleep(1)

pr = psutil.Process(p.pid)
children = all_children(pr)
assert len(children) > 0
p.kill()


class TestMonitor(object):
Expand All @@ -19,6 +44,10 @@ def test_simple(self):
def test_simple_with_interval(self):
monitor(self.p.pid, duration=3, interval=0.1)

def test_with_children(self, tmpdir):
# Test with current process since it has a subprocess (self.p)
monitor(os.getpid(), duration=3, include_children=True)

def test_logfile(self, tmpdir):
filename = tmpdir.join('test_logfile').strpath
monitor(self.p.pid, logfile=filename, duration=3)
Expand Down

0 comments on commit b4cb315

Please sign in to comment.