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

fixtures used lazily are not detected #39

Open
aaarrti opened this issue Sep 8, 2022 · 2 comments
Open

fixtures used lazily are not detected #39

aaarrti opened this issue Sep 8, 2022 · 2 comments

Comments

@aaarrti
Copy link

aaarrti commented Sep 8, 2022

Hi,
after I run pytest --dead-fixtures I get an output e.g.
image
To double check if ii is so, I run grep -r 'almost_uniform_1d' tests
and get
image.
So, the fixtures are clearly used, but not detected, because of lazy loading.
This is the plugin I use for lazy loading https://github.com/TvoroG/pytest-lazy-fixture

@jonatrios
Copy link
Contributor

jonatrios commented Sep 11, 2022

@aaarrti if you see source of pytest-lazy-fixture, you can notice that it is getting the fixture value from the method getfixturevalue from the built-in request fixture that pytest framework provides. So if you do this manually without using this plugin you will end up with same results.
Few days ago I've made a patch to this behaviour to solve a similar problem that I had that is also related to the issue #28 but the PR is sill open: #38
This could be a good use case to test if the changes to support this are working as expected, or if they need to be modified again to also work with the plugin pytest-lazy-fixture, so please use the fork that I made and then tell me if it also helps to solve your problem. https://github.com/jonatrios/pytest-deadfixtures/tree/feature/add_support_for_parametrize_fixtures

@aaarrti
Copy link
Author

aaarrti commented Sep 11, 2022

So, I installed pytest-dead-fixture from source. Not this is what I get as an output:

INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/pytest_deadfixtures-3.0.0-py3.9.egg/pytest_deadfixtures.py", line 219, in show_dead_fixtures
INTERNALERROR>     param_fixtures = get_parametrized_fixtures(session, available_fixtures)
INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/pytest_deadfixtures-3.0.0-py3.9.egg/pytest_deadfixtures.py", line 128, in get_parametrized_fixtures
INTERNALERROR>     return [
INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/pytest_deadfixtures-3.0.0-py3.9.egg/pytest_deadfixtures.py", line 128, in <listcomp>
INTERNALERROR>     return [
INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/pytest_deadfixtures-3.0.0-py3.9.egg/pytest_deadfixtures.py", line 131, in <lambda>
INTERNALERROR>     lambda x: x.fixturedef.argname in params_values, available_fixtures
INTERNALERROR>   File "/Users/artemsereda/anaconda3/envs/Quantus-3.9/lib/python3.9/site-packages/pytest_lazyfixture.py", line 197, in __eq__
INTERNALERROR>     return self.name == other.name
INTERNALERROR> AttributeError: 'str' object has no attribute 'name'

Unfortunately I'm not aware of the internals neither of pytest nor of the plugin, but it looks to me like the problem is that
because of lazy loading during the pytest-dead-fixture scan the fixture object is not there, but only the name of it, namely str.
So, should it be a feature request to pytest-dead-fixture? Should this be consider a bug in pytest-lazy-fixture?
Or should I just close the issue, as it will not work out?

@FyZzyss FyZzyss mentioned this issue Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants