Skip to content

Instantly share code, notes, and snippets.

@sanscore
Last active December 31, 2019 11:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanscore/d371763f8e88052891b16b4d65a1d2a8 to your computer and use it in GitHub Desktop.
Save sanscore/d371763f8e88052891b16b4d65a1d2a8 to your computer and use it in GitHub Desktop.
print(...) tracing for pytest.
import inspect
import pytest
def pytest_addhooks(pluginmanager):
print(inspect.currentframe().f_code.co_name)
def pytest_namespace():
print(inspect.currentframe().f_code.co_name)
def pytest_plugin_registered(plugin, manager):
print(inspect.currentframe().f_code.co_name)
def pytest_addoption(parser):
print(inspect.currentframe().f_code.co_name)
def pytest_configure(config):
print(inspect.currentframe().f_code.co_name)
def pytest_cmdline_parse(pluginmanager, args):
print(inspect.currentframe().f_code.co_name)
def pytest_cmdline_preparse(config, args):
print(inspect.currentframe().f_code.co_name)
def pytest_cmdline_main(config):
print(inspect.currentframe().f_code.co_name)
def pytest_load_initial_conftests(early_config, parser, args):
print(inspect.currentframe().f_code.co_name)
def pytest_collection(session):
print(inspect.currentframe().f_code.co_name)
def pytest_collection_modifyitems(session, config, items):
print(inspect.currentframe().f_code.co_name)
def pytest_collection_finish(session):
print(inspect.currentframe().f_code.co_name)
def pytest_ignore_collect(path, config):
print(inspect.currentframe().f_code.co_name)
def pytest_collect_directory(path, parent):
print(inspect.currentframe().f_code.co_name)
def pytest_collect_file(path, parent):
print(inspect.currentframe().f_code.co_name)
def pytest_collectstart(collector):
print(inspect.currentframe().f_code.co_name)
def pytest_itemcollected(item):
print(inspect.currentframe().f_code.co_name)
def pytest_collectreport(report):
print(inspect.currentframe().f_code.co_name)
def pytest_deselected(items):
print(inspect.currentframe().f_code.co_name)
def pytest_make_collect_report(collector):
print(inspect.currentframe().f_code.co_name)
def pytest_pycollect_makemodule(path, parent):
print(inspect.currentframe().f_code.co_name)
def pytest_pycollect_makeitem(collector, name, obj):
print(inspect.currentframe().f_code.co_name)
def pytest_pyfunc_call(pyfuncitem):
print(inspect.currentframe().f_code.co_name)
def pytest_generate_tests(metafunc):
print(inspect.currentframe().f_code.co_name)
def pytest_make_parametrize_id(config, val):
print(inspect.currentframe().f_code.co_name)
def pytest_runtestloop(session):
print(inspect.currentframe().f_code.co_name)
def pytest_itemstart(item, node):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_protocol(item, nextitem):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_logstart(nodeid, location):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_logfinish(nodeid, location):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_setup(item):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_call(item):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_teardown(item, nextitem):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_makereport(item, call):
print(inspect.currentframe().f_code.co_name)
def pytest_runtest_logreport(report):
print(inspect.currentframe().f_code.co_name)
def pytest_fixture_setup(fixturedef, request):
print(inspect.currentframe().f_code.co_name)
def pytest_fixture_post_finalizer(fixturedef):
print(inspect.currentframe().f_code.co_name)
def pytest_sessionstart(session):
print(inspect.currentframe().f_code.co_name)
def pytest_sessionfinish(session, exitstatus):
print(inspect.currentframe().f_code.co_name)
def pytest_unconfigure(config):
print(inspect.currentframe().f_code.co_name)
def pytest_assertrepr_compare(config, op, left, right):
print(inspect.currentframe().f_code.co_name)
def pytest_report_header(config, startdir):
print(inspect.currentframe().f_code.co_name)
def pytest_report_teststatus(report):
print(inspect.currentframe().f_code.co_name)
def pytest_terminal_summary(terminalreporter, exitstatus):
print(inspect.currentframe().f_code.co_name)
def pytest_logwarning(message, code, nodeid, fslocation):
print(inspect.currentframe().f_code.co_name)
def pytest_doctest_prepare_content(content):
print(inspect.currentframe().f_code.co_name)
def pytest_internalerror(excrepr, excinfo):
print(inspect.currentframe().f_code.co_name)
def pytest_keyboard_interrupt(excinfo):
print(inspect.currentframe().f_code.co_name)
def pytest_exception_interact(node, call, report):
print(inspect.currentframe().f_code.co_name)
def pytest_enter_pdb(config):
print(inspect.currentframe().f_code.co_name)
@pytest.fixture(autouse=True)
def auto_fixture(request):
print(inspect.currentframe().f_code.co_name)
@pytest.fixture(scope='session')
def session_fixture(request):
print(inspect.currentframe().f_code.co_name)
@pytest.fixture(scope='module')
def module_fixture(request):
print(inspect.currentframe().f_code.co_name)
@pytest.fixture(scope='class')
def class_fixture(request):
print(inspect.currentframe().f_code.co_name)
@pytest.fixture
def function_fixture(request):
print(inspect.currentframe().f_code.co_name)
import inspect
def test_trace(session_fixture, module_fixture, class_fixture, function_fixture):
print(inspect.currentframe().f_code.co_name)
@sanscore
Copy link
Author

sanscore commented Apr 2, 2018

$ pytest --capture=no test_trace.py
pytest_addhooks
pytest_addoption
pytest_namespace
pytest_plugin_registered
[...]
pytest_plugin_registered
pytest_cmdline_preparse
pytest_cmdline_main
pytest_plugin_registered
pytest_plugin_registered
pytest_plugin_registered
pytest_configure
pytest_plugin_registered
pytest_plugin_registered
pytest_sessionstart
pytest_plugin_registered
==== test session starts ====
platform darwin -- Python 2.7.14, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
pytest_report_header
rootdir: /Users/u205/tmp/pytest-trace, inifile:
plugins: xdist-1.22.2, metadata-1.6.0, html-1.16.1, forked-0.2, cov-2.5.1
pytest_collection
pytest_collectstart
pytest_make_collect_report
pytest_collect_file
pytest_pycollect_makemodule
collecting 0 items                                                                                                                                                                                                                                                                                                                                                         pytest_collectreport
pytest_collectstart
pytest_make_collect_report
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_generate_tests
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_pycollect_makeitem
pytest_itemcollected
collecting 1 item                                                                                                                                                                                                                                                                                                                                                          pytest_collectreport
pytest_collection_modifyitems
collected 1 item
pytest_collection_finish
pytest_runtestloop
pytest_runtest_protocol

test_trace.py pytest_runtest_logstart
pytest_runtest_setup
pytest_fixture_setup
session_fixture
pytest_fixture_setup
module_fixture
pytest_fixture_setup
class_fixture
pytest_fixture_setup
auto_fixture
pytest_fixture_setup
function_fixture
pytest_runtest_makereport
pytest_report_teststatus
pytest_runtest_logreport
pytest_runtest_call
pytest_pyfunc_call
test_trace
pytest_runtest_makereport
pytest_report_teststatus
.pytest_runtest_logreport
pytest_runtest_teardown
pytest_fixture_post_finalizer
pytest_fixture_post_finalizer
pytest_fixture_post_finalizer
pytest_fixture_post_finalizer
pytest_fixture_post_finalizer
pytest_runtest_makereport
pytest_report_teststatus
pytest_runtest_logreport
pytest_runtest_logfinish
pytest_sessionfinish

pytest_terminal_summary

==== 1 passed in 0.05 seconds ====
pytest_unconfigure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment