Environment: platform qnx -- Python 2.7.12, pytest-4.6.9, py-1.8.1, pluggy-0.13.1 plugins: json-report-1.2.1, shell-0.2.3
Note: I know Python2.7 is old and unsupported, but there's no other version available for QNX at the moment.
Problem:
I'm running a tests that should kill a service when a certain keyword appears in its log. For this, I need it to be ran in the background. For this, I'm using the following shell command:
def test_kill_process():
expected_output="XXXXXXXXX"
expected_rc=0
check_kill_process(expected_output, expected_rc)
import os
def check_kill_process(expected_output, expected_rc):
test_log = File(r"/path/to/log")
erase_log_entry = "Action"
service=MyService()
service.start()
sleep(2)
kill_command = "tail -f " + test_log.file_path + " | grep --line-buffered " + erase_log_entry + \
" | while read ; do kill " + service.pid + " ; done &"
os.popen(kill_command)
service.action()
f = open(test_log.file_path, "r")
output = f.read()
assert re.search(expected_output, output)
========================================================================
Without Pytest or even Python, works like a charm.
If I try using subprocess module to run the command, the test freezes indefinitely. If I try to use os.popen or os.system, the command ends in error:
tail: read failed in '/path/to/logfile' (Invalid argument)
Moreover, if I try the same thing, with only a "cat" I get this:
--stdout--: Broken pipe
Thanks in advance if anyone has any ideea!