If I execute tests on local machine, I can see the console output from the test case. However, the console output is not captured while running tests on remote machine using pytest. Here is the sample test case -
test_sample.py
import os
import pytest
@pytest.mark.set1
def test_command():
output = os.popen("ifconfig")
print(output.read())
pytest.ini
[pytest]
markers =
set1: mark a test as a set1.
set2: mark a test as a set2.
~/.ssh/config
Host ubuntu
HostName 10.203.114.68
User root
Port 22
IdentityFile ~/.ssh/id_rsa
Pytest Command to execute tests on local VM
py.test -s -m set1 -k test_command -v
Console Output
========================================================================================================= test session starts =========================================================================================================
platform linux -- Python 3.6.12, pytest-6.0.2, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3.6
cachedir: .pytest_cache
metadata: {'Python': '3.6.12', 'Platform': 'Linux-4.4.0-142-generic-x86_64-with-Ubuntu-16.04-xenial', 'Packages': {'pytest': '6.0.2', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1', 'forked': '1.3.0', 'xdist': '2.1.0', 'metadata': '1.11.0'}}
rootdir: /home/kulkarniabhi/pytaf, configfile: pytest.ini
plugins: html-2.1.1, forked-1.3.0, xdist-2.1.0, metadata-1.11.0
collected 19 items / 18 deselected / 1 selected
test_demo5.py::test_command ens160 Link encap:Ethernet HWaddr 00:50:56:93:9a:1d
inet addr:10.198.36.31 Bcast:10.198.39.255 Mask:255.255.252.0
inet6 addr: fe80::250:56ff:fe93:9a1d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1748980902 errors:0 dropped:5419 overruns:0 frame:0
TX packets:54277009 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:252392842770 (252.3 GB) TX bytes:101276948055 (101.2 GB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5683112 errors:0 dropped:0 overruns:0 frame:0
TX packets:5683112 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:1720657136 (1.7 GB) TX bytes:1720657136 (1.7 GB)
PASSED
================================================================================================== 1 passed, 18 deselected in 0.03s ===================================================================================================
Pytest Command to execute tests on remote VM ubuntu
py.test -d --tx ssh=ubuntu//python=python3 --rsyncdir ~/pytaf/ -s -m set1 -k test_command -v
Console Output
========================================================================================================= test session starts =========================================================================================================
platform linux -- Python 3.6.12, pytest-6.0.2, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3.6
cachedir: .pytest_cache
metadata: {'Python': '3.6.12', 'Platform': 'Linux-4.4.0-142-generic-x86_64-with-Ubuntu-16.04-xenial', 'Packages': {'pytest': '6.0.2', 'py': '1.9.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1', 'forked': '1.3.0', 'xdist': '2.1.0', 'metadata': '1.11.0'}}
rootdir: /home/kulkarniabhi/pytaf, configfile: pytest.ini
plugins: html-2.1.1, forked-1.3.0, xdist-2.1.0, metadata-1.11.0
gw0 Iroot@10.203.114.68's password: **********
[gw0] linux Python 3.8.5 cwd: /home/bit9qa/pyexecnetcache
[gw0] Python 3.8.5 (default, Jul 28 2020, 12:59:40) -- [GCC 9.3.0]
gw0 [1]
scheduling tests via LoadScheduling
test_demo5.py::test_command
[gw0] PASSED test_demo5.py::test_command
========================================================================================================== 1 passed in 8.04s =========================================================================================================
**My pytest version on both local and remote vm ==> **
[root@localhost]$ python3.6 -m py.test --version pytest 6.0.2
I have already verified that --capture / -s option is supported by the latest pytest-xdist
https://github.com/pytest-dev/pytest/issues/680
There is NO need to apply the following workaround
pytest + xdist without capturing output?