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

Plugins loaded via PYTEST_PLUGINS or pytest_plugins are not reported #12615

Open
3 of 4 tasks
mtelka opened this issue Jul 16, 2024 · 3 comments
Open
3 of 4 tasks

Plugins loaded via PYTEST_PLUGINS or pytest_plugins are not reported #12615

mtelka opened this issue Jul 16, 2024 · 3 comments
Labels
topic: config related to config handling, argument parsing and config file topic: reporting related to terminal output and user-facing messages and errors

Comments

@mtelka
Copy link

mtelka commented Jul 16, 2024

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

When I load a plugin using the PYTEST_ADDOPTS environment variable then the plugin is properly reported in the list of plugins:

$ env - PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_ADDOPTS='-p randomly' pytest --setup-plan
============================= test session starts ==============================
platform sunos5 -- Python 3.9.19, pytest-8.2.2, pluggy-1.5.0
Using --randomly-seed=2747766829
rootdir: /tmp/test
plugins: randomly-3.15.0
collected 0 items                                                              

============================ no tests ran in 0.03s =============================
$

When I try to achieve the same using the PYTEST_PLUGINS environment variable then the plugin is not listed in the list of plugins:

$ env - PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_PLUGINS=pytest_randomly pytest --setup-plan
============================= test session starts ==============================
platform sunos5 -- Python 3.9.19, pytest-8.2.2, pluggy-1.5.0
Using --randomly-seed=3835907952
rootdir: /tmp/test
collected 0 items                                                              

============================ no tests ran in 0.03s =============================
$

but the plugin is apparently properly loaded (please note --randomly-seed).

It would be great to see plugins loaded via the PYTEST_PLUGINS environment variable reported too to avoid confusion.

EDIT: the same problem is seen when the pytest_plugins global variable is used to load plugins.

@mtelka
Copy link
Author

mtelka commented Jul 16, 2024

I found that with the following patch:

--- /usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py.orig
+++ /usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py
@@ -835,7 +835,7 @@
     ) -> None:
         plugins = _get_plugin_specs_as_list(spec)
         for import_spec in plugins:
-            self.import_plugin(import_spec)
+            self.import_plugin(import_spec, consider_entry_points=True)

     def import_plugin(self, modname: str, consider_entry_points: bool = False) -> None:
         """Import a plugin with ``modname``.

the randomly plugin is properly listed in the list of plugins (but I had to use PYTEST_PLUGINS=randomly instead of PYTEST_PLUGINS=pytest_randomly):

$ env - PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_PLUGINS=randomly pytest --setup-plan
============================= test session starts ==============================
platform sunos5 -- Python 3.9.19, pytest-8.2.2, pluggy-1.5.0
Using --randomly-seed=1218696459
rootdir: /tmp/test
plugins: randomly-3.15.0
collected 0 items                                                              

============================ no tests ran in 0.03s =============================
$

mtelka added a commit to mtelka/pytest that referenced this issue Jul 16, 2024
This fixes two issues related to the `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable:

* plugins loaded this way are not listed in the list of plugins,
* it is not possible to load plugins using their names in `entry_points.txt`
  files.

Fixes pytest-dev#12615.
mtelka added a commit to mtelka/pytest that referenced this issue Jul 16, 2024
This fixes two issues related to the `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable:

* plugins loaded this way are not listed in the list of plugins,
* it is not possible to load plugins using their names in `entry_points.txt`
  files.

Fixes pytest-dev#12615.
mtelka added a commit to mtelka/pytest that referenced this issue Jul 16, 2024
This fixes two issues related to the `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable:

* plugins loaded this way are not listed in the list of plugins,
* it is not possible to load plugins using their names in `entry_points.txt`
  files.

Fixes pytest-dev#12615.
mtelka added a commit to mtelka/pytest that referenced this issue Jul 16, 2024
This fixes two issues related to the `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable:

* plugins loaded this way are not listed in the list of plugins,
* it is not possible to load plugins using their names in `entry_points.txt`
  files.

Fixes pytest-dev#12615.
mtelka added a commit to mtelka/pytest that referenced this issue Jul 16, 2024
This fixes two issues related to the `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable:

* plugins loaded this way are not listed in the list of plugins,
* it is not possible to load plugins using their names in `entry_points.txt`
  files.

See pytest-dev#12615.
@mtelka
Copy link
Author

mtelka commented Jul 16, 2024

I found that with the following patch:

--- /usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py.orig
+++ /usr/lib/python3.9/vendor-packages/_pytest/config/__init__.py
@@ -835,7 +835,7 @@
     ) -> None:
         plugins = _get_plugin_specs_as_list(spec)
         for import_spec in plugins:
-            self.import_plugin(import_spec)
+            self.import_plugin(import_spec, consider_entry_points=True)

     def import_plugin(self, modname: str, consider_entry_points: bool = False) -> None:
         """Import a plugin with ``modname``.

the randomly plugin is properly listed in the list of plugins (but I had to use PYTEST_PLUGINS=randomly instead of PYTEST_PLUGINS=pytest_randomly):

$ env - PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_PLUGINS=randomly pytest --setup-plan
============================= test session starts ==============================
platform sunos5 -- Python 3.9.19, pytest-8.2.2, pluggy-1.5.0
Using --randomly-seed=1218696459
rootdir: /tmp/test
plugins: randomly-3.15.0
collected 0 items                                                              

============================ no tests ran in 0.03s =============================
$

This was split out to #12624.

@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors topic: config related to config handling, argument parsing and config file labels Jul 21, 2024
@mtelka
Copy link
Author

mtelka commented Jul 22, 2024

The problem seems to be in the import_plugin() function.

@mtelka mtelka changed the title Plugins loaded via PYTEST_PLUGINS environment variable are not reported Plugins loaded via PYTEST_PLUGINS or pytest_plugins are not reported Jul 22, 2024
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 topic: reporting related to terminal output and user-facing messages and errors
Projects
None yet
Development

No branches or pull requests

2 participants