Guest User

Untitled

a guest
Jul 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. from subprocess import Popen, PIPE
  2.  
  3. class foo(object):
  4.  
  5. def __init__(self):
  6. self.process = None
  7. self.command = 'some command'
  8.  
  9. def _start_process(self, duration):
  10. self.process = Popen([self.command, '-d'], stdout=PIPE)
  11.  
  12. def _terminate_process(self):
  13. self.process.terminate()
  14.  
  15. import pytest
  16. from _pytest.monkeypatch import MonkeyPatch
  17. from mock import MagicMock, patch
  18. monkeypatch = MonkeyPatch()
  19. import file.foo
  20.  
  21. def bar():
  22. test_object = file.foo()
  23. monkeypatch.setattr('subprocess.Popen', MagicMock())
  24. test_object._start_process()
Add Comment
Please, Sign In to add comment