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

Pytest should printout the reason of test skipping inline. #4326

Closed
wb137 opened this issue Nov 7, 2018 · 3 comments
Closed

Pytest should printout the reason of test skipping inline. #4326

wb137 opened this issue Nov 7, 2018 · 3 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch

Comments

@wb137
Copy link

wb137 commented Nov 7, 2018

AFAIK Pytest print results of tests in the form:

File1.py::Class1::test_1 PASSED                               [ 50%]
File2.py::Class2::test_2 SKIPPED                              [100%]

However it would be great if by adding before the test_2 the following line:

    @pytest.mark.skip('Class created not for Linux')
    def test_2(self,...

we could get the following result (inline skipped reason):

File1.py::Class1::test_1 PASSED                               [ 50%]
File2.py::Class2::test_2 SKIPPED: Class created not for Linux [100%]

where the reason is easy identified during displaying the result.
I didn't find a solution in the pytest options.
I've found that this can be achieved (definitely not perfect solution, but I am using it) by replacing one line in the file runner.py in the function pytest_report_teststatus:

def pytest_report_teststatus(report):
    if report.when in ("setup", "teardown"):
        if report.failed:
            #      category, shortletter, verbose-word
            return "error", "E", "ERROR"
        elif report.skipped:
            return "skipped", "s", "SKIPPED"
        else:
            return "", "", ""

by the following:

def pytest_report_teststatus(report):
    if report.when in ("setup", "teardown"):
        if report.failed:
            #      category, shortletter, verbose-word
            return "error", "E", "ERROR"
        elif report.skipped:
            return "skipped", "s", "SKIPPED" + ": "+str(report.longrepr[2][9:] )
        else:
            return "", "", ""

pip list:

argparse (1.2.1)
beautifulsoup4 (4.3.2)
cffi (0.8.6)
chardet (2.3.0)
Click (7.0)
colorama (0.3.2)
cryptography (0.6.1)
decorator (3.4.0)
defusedxml (0.4.1)
docopt (0.6.2)
docutils (0.12)
Flask (1.0.2)
grip (4.5.2)
html5lib (0.999)
itsdangerous (1.1.0)
Jinja2 (2.10)
joblib (0.8.3)
lxml (3.4.0)
Markdown (3.0.1)
MarkupSafe (1.0)
matplotlib (1.4.2)
mock (1.0.1)
ndg-httpsclient (0.3.2)
nose (1.3.4)
numexpr (2.4)
numpy (1.8.2)
openpyxl (1.7.0)
pandas (0.14.1)
path-and-address (2.0.1)
pexpect (3.2)
Pillow (2.6.1)
pip (1.5.6)
ply (3.4)
pyasn1 (0.1.7)
pycparser (2.10)
pycups (1.9.63)
pycurl (7.19.5)
Pygments (2.0.1)
pygobject (3.14.0)
pyOpenSSL (0.14)
pyparsing (2.0.3)
pysmbc (1.0.15.3)
python-apt (0.9.3.12)
python-dateutil (2.2)
python-debian (0.1.27)
python-debianbts (1.11)
pytz (2012c)
reportbug (6.6.3)
reportlab (3.1.8)
requests (2.4.3)
roman (2.0.0)
scipy (0.14.0)
setuptools (5.5.1)
simplejson (3.6.5)
six (1.8.0)
SOAPpy (0.12.22)
statsmodels (0.4.2)
tables (3.1.1)
urllib3 (1.9.1)
vboxapi (1.0)
Werkzeug (0.14.1)
wheel (0.24.0)
wsgiref (0.1.2)
wstools (0.4.3)
xlrd (0.9.2)
xlwt (0.7.5)
pytest --version
This is pytest version 3.10.0, imported from /usr/local/lib/python3.4/dist-packages/pytest.py
uname -a
Linux francisco 4.9.0-0.bpo.8-amd64 #1 SMP Debian 4.9.110-3+deb9u5~deb8u1 (2018-10-03) x86_64 GNU/Linux
@nicoddemus nicoddemus added the type: enhancement new feature or API change, should be merged into features branch label Nov 7, 2018
@nicoddemus
Copy link
Member

Thanks for the suggestion @wb137!

@nicoddemus nicoddemus added the topic: reporting related to terminal output and user-facing messages and errors label Nov 7, 2018
@blueyed
Copy link
Contributor

blueyed commented Nov 8, 2018

This would only be done in verbose mode then, yes?

@Zac-HD
Copy link
Member

Zac-HD commented Dec 7, 2018

Closing as duplicate of #2044.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

5 participants