5

In my pytest script, I need to customize the pytest-HTML report for capturing the stdout at the same time writing into the console as I have user input in my automated test.

test_TripTick.py

import os
import sys
import pytest

from Process import RunProcess
from recordtype import recordtype
from pip._vendor.distlib.compat import raw_input

@pytest.fixture(scope="module")
def Process(request):
    # print('\nProcess setup - module fixture')
    fileDirectory = os.path.abspath(os.path.dirname(__file__))
    configFilePath = os.path.join(fileDirectory, 'ATR220_Config.json')
    process = RunProcess.RunProcess()
    process.SetConfigVariables(configFilePath)
    process.GetComPort(["list=PID_0180"])

    def fin():
        sys.exit()
        request.addfinalizer(fin)

    return process


def test_WipeOutReader(Process):
    assert Process.WipeOutTheReader() == True


def test_LoadingKeysIntoMemoryMap(Process):
    assert Process.LoadingKeysIntoMemoryMap() == True


def test_LoadingFW(Process):  # only use bar
    assert Process.LoadingFW() == True


def test_LoadingSBL(Process):
    assert Process.LoadingSBL() == True


def test_CCIDReadForPaymentCards(Process):
    assert Process.CCIDReadWrite('Payment Card') == True

Currently, if I run the following command from the windows command line, I get output on the console, but no captured output on the HTML report.

pytest C:\Projects\TripTickAT\test_TripTick.py -s --html=Report.html --verbose

Also, I would like to know the programmatic way of customizing the HTML report where I can update the file name, ordering test based on time of the execution and capturing the std-out.

Raj
  • 151
  • 1
  • 14

1 Answers1

6

You can use additional flags with the pytest command:

  • --capture sys and -rP for passed tests.
  • --capture sys and -rF for failed tests

By clicking the show All details button you can see the console log in the html document as well, as shown in the output:

The grey area is the stid out`

Note that this is just a partial screenshot, but you can scroll down the output to see all the console logs. The grey area is the console output. The logs are printed on the command line console as well as in the html logs console.

NB: I am not aware of a command line level flag that works regardless of failed or passed tests.

trincot
  • 317,000
  • 35
  • 244
  • 286