Skip to content

pytest.skip inside doctests does not work (UnexpectedException) #4911

@tkf

Description

@tkf

pytest.skip docstring says "This function should be called only during testing (setup, call or teardown)". However, calling pytest.skip inside a doctest is counted as a failure:

$ ls
env  test.txt

$ cat test.txt
>>> import pytest
>>> pytest.skip("Skip doctest")

$ env/bin/pytest
================== test session starts ==================
platform linux -- Python 3.7.0, pytest-4.3.0, py-1.8.0, pluggy-0.9.0
rootdir: /tmp/tmp.YVVwv7GVVo, inifile:
collected 1 item

test.txt F                                        [100%]

======================= FAILURES ========================
__________________ [doctest] test.txt ___________________
001 >>> import pytest
002 >>> pytest.skip("Skip doctest")
UNEXPECTED EXCEPTION: Skip doctest
Traceback (most recent call last):

  File "/usr/lib64/python3.7/doctest.py", line 1329, in __run
    compileflags, 1), test.globs)

  File "<doctest test.txt[1]>", line 1, in <module>

  File "/tmp/tmp.YVVwv7GVVo/env/lib/python3.7/site-packages/_pytest/outcomes.py", line 98, in skip
    raise Skipped(msg=msg, allow_module_level=allow_module_level)

Skipped: Skip doctest

/tmp/tmp.YVVwv7GVVo/test.txt:2: UnexpectedException
=============== 1 failed in 0.01 seconds ================

Would it be possible to make pytest.skip work inside doctests?

System information:
$ env/bin/pip list
Package        Version
-------------- -------
atomicwrites   1.3.0
attrs          19.1.0
more-itertools 6.0.0
pip            19.0.3
pluggy         0.9.0
py             1.8.0
pytest         4.3.0
setuptools     40.8.0
six            1.12.0
wheel          0.33.1

$ env/bin/pytest --version
This is pytest version 4.3.0, imported from /tmp/tmp.YVVwv7GVVo/env/lib/python3.7/site-packages/pytest.py

$ uname -a
Linux tkf-xps 4.14.61-1-lts #1 SMP Mon Aug 6 21:07:39 CEST 2018 x86_64 GNU/Linux

$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
ID_LIKE=archlinux
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions