I have a test file which run some binary executable and check the output. The test looks like this:
#! /usr/bin/env python
from subprocess import Popen, PIPE
import unittest
import sys
class MyTest(unittest.TestCase):
PATH = './app'
def setUp(self):
pass
def tearDown(self):
pass
@staticmethod
def run_subprocess(cmd):
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
return stdout.decode('ascii'), stderr
def test_case1(self):
stdout, stderr = self.run_subprocess([self.PATH, some_cmd])
def test_case2(self):
stdout, stderr = self.run_subprocess([self.PATH, some_other_cmd])
if __name__ =="__main__":
if len(sys.argv) < 2:
raise AttributeError("Usage: python run_test.py app_path")
TestBingbangboom.PATH = sys.argv[1]
unittest.main(argv=['first-arg-is-ignored'], exit=False)
I can run the test with $[python run_test.py app_path
. But how can I do the same with pytest
:
$pytest app_path