-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
I have a conftest.py I've been using to try to test the available hook functions.
import pytest
print('conftest.py')
def pytest_load_initial_conftests(early_config, parser, args):
print(early_config)
print(parser)
print(args)
def pytest_cmdline_parse(pluginmanager, args):
print(pluginmanager)
print(args)
def pytest_cmdline_main(config):
print(config)
def pytest_cmdline_preparse(config, args):
print(config)
print(args)
The values for pytest_cmdline_main and pytest_cmdline_preparse never get printed, so I think they're not being called. When I look in the debugger, the latter hooks seem to be called by the line
Line 167 in 81ad185
return pluginmanager.hook.pytest_cmdline_parse( |
Pdb) b /usr/local/lib/python3.6/site-packages/_pytest/config.py:157
Breakpoint 1 at /usr/local/lib/python3.6/site-packages/_pytest/config.py:157
(Pdb) c
> /usr/local/lib/python3.6/site-packages/_pytest/config.py(157)_prepareconfig()
-> return pluginmanager.hook.pytest_cmdline_parse(
(Pdb) for i in config.hook.pytest_cmdline_parse._nonwrappers: i.function.__module__
'_pytest.config'
The only hook at this point is _pytest.config.Config.pytest_cmdline_parse
, which gets called. Later on, the hook in my conftest.py is added, but I don't think this list of hooks is examined again after this initial call. Having __init__.py
in the directory or not doesn't seem to matter, the first two hooks don't get executed. I haven't checked more complicated possible package configurations.
If this is intended behavior, it's not very transparent, and the documentation doesn't explain what's needed to get the first two hooks actually called.
$ pip list
asn1crypto (0.22.0)
Babel (2.3.4)
certifi (2017.4.17)
cffi (1.10.0)
chardet (3.0.4)
cryptography (1.9)
debtcollector (1.14.0)
enum34 (1.1.6)
Fabric (1.13.2)
funcsigs (1.0.2)
httplib2 (0.10.3)
idna (2.5)
ipaddress (1.0.18)
iso8601 (0.1.11)
keystoneauth1 (2.21.0)
kubernetes (2.0.0)
mercurial (4.2.1)
monotonic (1.3)
msgpack-python (0.4.8)
netaddr (0.7.19)
netifaces (0.10.6)
oauth2client (4.1.1)
oslo.i18n (3.15.3)
oslo.serialization (2.18.0)
oslo.utils (3.26.0)
paramiko (2.1.2)
pbr (3.0.1)
pexpect (4.2.1)
pip (9.0.1)
positional (1.1.1)
prettytable (0.7.2)
ptyprocess (0.5.1)
py (1.4.34)
pyasn1 (0.2.3)
pyasn1-modules (0.0.9)
pycparser (2.17)
pyparsing (2.2.0)
pytest (3.1.2)
python-dateutil (2.6.0)
python-novaclient (9.0.0)
pytz (2017.2)
PyYAML (3.12)
Reindent (0.1.1)
requests (2.17.3)
rsa (3.4.2)
setuptools (32.1.0)
simplejson (3.10.0)
six (1.10.0)
stevedore (1.23.0)
urllib3 (1.21.1)
websocket-client (0.44.0)
wheel (0.29.0)
wrapt (1.10.10)
$ pytest --version
This is pytest version 3.1.1, imported from /usr/local/lib/python3.6/site-packages/pytest.py
setuptools registered plugins:
pytest-metadata-1.5.0 at ~/Library/Python/3.6/lib/python/site-packages/pytest_metadata/plugin.py
pytest-html-1.15.1 at ~/Library/Python/3.6/lib/python/site-packages/pytest_html/plugin.py
pytest-xprocess-0.12.1 at /usr/local/lib/python3.6/site-packages/pytest_xprocess.py
pytest-cov-2.5.1 at /usr/local/lib/python3.6/site-packages/pytest_cov/plugin.py
This is on MacOS X 10.12.5 and Python 3.6 installed with Homebrew.