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

plugin hook pytest_runtest_teardown runs on skipped test #3385

Closed
lodagro opened this issue Apr 11, 2018 · 6 comments
Closed

plugin hook pytest_runtest_teardown runs on skipped test #3385

lodagro opened this issue Apr 11, 2018 · 6 comments
Labels
topic: config related to config handling, argument parsing and config file type: question general question, might be closed after 2 weeks of inactivity

Comments

@lodagro
Copy link

lodagro commented Apr 11, 2018

conftest.py

import pytest


class MyPlugin:

    def pytest_runtest_setup(self, item):
        raise Exception

    def pytest_runtest_teardown(self, item):
        raise Exception


def pytest_configure(config):
    config.pluginmanager.register(MyPlugin(), "myplugin")

test_teardown.py

import pytest

@pytest.mark.skip
def test_somestuff():
    pass

run output (with relevant version info)

=============================== test session starts ================================
platform linux -- Python 3.6.3, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
metadata: {'Python': '3.6.3', 'Platform': 'Linux-2.6.32-358.23.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago', 'Packages': {'pytest': '3.5.0', 'py': '1.5.3', 'pluggy': '0.4.0'}, 'Plugins': {'metadata': '1.5.0', 'hypothesis': '3.11.6'}}
rootdir: /projects/hardware/BCM65550/users/wovermei/sandbox/plugin_teardown, inifile:
plugins: metadata-1.5.0, hypothesis-3.11.6
collected 1 item                                                                   

test_teardown.py sE                                                          [100%]

====================================== ERRORS ======================================
_______________________ ERROR at teardown of test_somestuff ________________________

self = <conftest.MyPlugin object at 0x7f0dbfaf1fd0>
item = <Function 'test_somestuff'>

    def pytest_runtest_teardown(self, item):
>       raise Exception
E       Exception

conftest.py:10: Exception
======================== 1 skipped, 1 error in 0.05 seconds ========================
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1563 (All pytest tests skipped), #1364 (disallow test skipping), #732 (Unregistered plugin still receives hook calls), #2544 (Run tests truly programmatically), and #367 (Skip tests that require a fixture).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Apr 11, 2018
@RonnyPfannschmidt
Copy link
Member

i recall thats per design, and unittest disagrees

@RonnyPfannschmidt
Copy link
Member

pytest/_pytest/runner.py

Lines 69 to 87 in e012dbe

def runtestprotocol(item, log=True, nextitem=None):
hasrequest = hasattr(item, "_request")
if hasrequest and not item._request:
item._initrequest()
rep = call_and_report(item, "setup", log)
reports = [rep]
if rep.passed:
if item.config.option.setupshow:
show_test_item(item)
if not item.config.option.setuponly:
reports.append(call_and_report(item, "call", log))
reports.append(call_and_report(item, "teardown", log,
nextitem=nextitem))
# after all teardown hooks have been called
# want funcargs and request info to go away
if hasrequest:
item._request = False
item.funcargs = None
return reports
- its pretty much baked in - setup always, teardown always, call only when setup passes

@nicoddemus nicoddemus added type: question general question, might be closed after 2 weeks of inactivity topic: config related to config handling, argument parsing and config file and removed type: bug problem that needs to be addressed labels Apr 11, 2018
@lodagro
Copy link
Author

lodagro commented Apr 12, 2018

In this case setup did not run, only teardown.

Is there a way to know in the teardown hook that the test was skipped (or do i need to track this myself)?

@RonnyPfannschmidt
Copy link
Member

@lodagro skip is evaluated as part of setup, so setup did in fact run a bit
currently you need to track yourself,

can you outline the use-case of the plugin, if we get a handle on what you want to do we may be able to point out a nice alternative

@lodagro
Copy link
Author

lodagro commented Apr 12, 2018

The plugin is managing a database, used to store data collected during the tests.
Tracking myself is fine, i was not expecting the teardown to run on a skipped test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: config related to config handling, argument parsing and config file type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants