Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report fixture setup and teardown #131

Closed
iwanb opened this issue Sep 7, 2017 · 13 comments · Fixed by #271
Closed

Report fixture setup and teardown #131

iwanb opened this issue Sep 7, 2017 · 13 comments · Fixed by #271

Comments

@iwanb
Copy link

iwanb commented Sep 7, 2017

Hi,
I would like to vizualize when fixtures are set up and teared down, the time they take, their output and if they failed.
I think they could be added in the Results section, filtered by default, around the tests.
It might add a lot of information, so it would look better along with #33

Would you be open to such an enchancement? (It could be optional if needed.)
Do you see issues it might create? Would you do it in a different way?

@davehunt
Copy link
Collaborator

davehunt commented Sep 7, 2017

There are already command line options for showing these, as shown below from pytest --help:

  --setup-only          only setup fixtures, do not execute tests.
  --setup-show          show setup of fixtures while executing tests.
  --setup-plan          show what fixtures and tests would be executed but
                        don't execute anything.

I don't think any of this will be displayed in the HTML report though. I'd be happy to merge a patch that adds the fixture details to the HTML report when --setup-show is specified.

@iwanb
Copy link
Author

iwanb commented Sep 7, 2017

True I did not think of that option, I will have a look at how it is implemented in pytest.
I will see what I can do and come back with a PR.

@david-fliguer-ws
Copy link

Hi, sorry for the bump but any news about this ?
In my case before the first test is run I do a series of actions and I want to output to the HTML report some information about it
Any workaround that can be done by now in a more or less clean way ? (Like saving all the text in a variable and then adding it manually to the HTML) ?

@iwanb
Copy link
Author

iwanb commented Mar 23, 2018

I have not really looked into it yet.

It should be easy to make a workaround adding to pytest-html extra content from the pytest_fixture_setup hook.

@wangtina
Copy link

wangtina commented Jul 6, 2018

@iwanb @davehunt any news about this question?
I have the same question with #145 Teardown log not shown in html

in my code, create a logger in setup_class ;and i logged some information in both setup ,testcase and teardown method;and using "pytest -v test_logs.py --html=reports\test.html" to run pytest cases

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/07/6 11:16
# @File    : test_logs.py
# @Software: PyCharm Community Edition
# @项目     : test
import os
import logging.config
import vnflib


class TestLogsToHtml(object):

    def setup_class(self):
        pyname = os.path.splitext(os.path.basename(__file__))[0]
        # read logger configuration
        logging.config.fileConfig('conf/logging.conf', defaults={'logfile': vnflib.getlogfilename(pyname)})
        # create a logger
        self.logger = logging.getLogger('root')
        self.logger.info("****************setup_class****************")

    # run after every case
    def teardown(self):# or use "capfd" for fd-level
        self.logger.info("****************teardown_method****************")

    def test_logsToHtml(self):
        self.logger.info("****************test_logsToHtml****************")
        pass

run pytest case using

pytest -v test_logs.py --html=reports\test.html

html report only show logs in setup_class and testcase ;but Teardown log not shown in html
logs in html

  • setup
  • testcase
  • teardown

image

@thesupershan
Copy link

Just wanna bump this, any chance someone can look into a fix?

@csm10495
Copy link
Member

I'm curious, if we see a 'teardown' event come in instead of a 'call' can we just delete the last row of html and create a new one then as if it had been a 'call'.. (Then also fix test counts).

@ruck94301
Copy link

Hi, with pytest 4.6.11, this is a problem in "captured logs", but not in "live logs". Showing both live & captured logs,
(pytest -r A --log-cli-level=DEBUG)
note that the teardown logrecords are missing from captured logs, but not missing from live logs.
Is there a workaround that I'm not seeing? OtherwiseI should use live log if it's important to me.
image

@gnikonorov
Copy link
Member

Hi @ruck94301. What version of this plugin are you using?

@ruck94301
Copy link

sorry, are you looking for 4.6.11 or something else?

@ruck94301
Copy link

ruck94301 commented Nov 4, 2020

oh right, I suppose the python version is important context for reproducing, sorry for not including that.
============================= test session starts ============================= platform win32 -- Python 2.7.18, pytest-4.6.11, py-1.9.0, pluggy-0.13.1

@gnikonorov
Copy link
Member

@ruck94301 is this an issue with pytest or pytest-html?

@ruck94301
Copy link

ruck94301 commented Nov 5, 2020

I'm saying pytest. I'm not using pytest-html. Maybe my observation helps explain the behavior seen pytest-html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants