You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i'm trying to create a pytest_xdist_auto_num_workers hook that should only be registered if the user runs pytest with the xdist plugin enabled, otherwise it will crash due to the hook name being unknown:
however it doesn't seem to work. the DeferPlugin gets registered but the pytest_xdist_auto_num_workers hook never gets called. i believe this is because pytest_xdist_auto_num_workers gets called before pytest_configure.
i considered using the PYTEST_XDIST_AUTO_NUM_WORKERS environment variable, but that won't work in this case because the logic i want to use to determine the new value needs to be based on the default value, which the environment variable does not contain.
attempting to import xdist before registering the hook
which works most of the time, but if the user runs pytest with -p no:xdist, it will crash because the xdist module exists but the plugin is disabled, causing it to attempt to register the hook when pytest would not recognize it.
The text was updated successfully, but these errors were encountered:
perhaps the documentation could be updated to mention this, as believe it would be a common use case to only want to register the hook when the plugin is active.
the problem
i'm trying to create a
pytest_xdist_auto_num_workers
hook that should only be registered if the user runs pytest with the xdist plugin enabled, otherwise it will crash due to the hook name being unknown:according to the pytest docs, i can accomplish it like so:
however it doesn't seem to work. the
DeferPlugin
gets registered but thepytest_xdist_auto_num_workers
hook never gets called. i believe this is becausepytest_xdist_auto_num_workers
gets called beforepytest_configure
.attempted workarounds
PYTEST_XDIST_AUTO_NUM_WORKERS
environment variablei considered using the
PYTEST_XDIST_AUTO_NUM_WORKERS
environment variable, but that won't work in this case because the logic i want to use to determine the new value needs to be based on the default value, which the environment variable does not contain.attempting to import
xdist
before registering the hooki tried doing this:
which works most of the time, but if the user runs pytest with
-p no:xdist
, it will crash because the xdist module exists but the plugin is disabled, causing it to attempt to register the hook when pytest would not recognize it.The text was updated successfully, but these errors were encountered: