dev-petrov / pytest-lazy-fixtures

Allows you to use fixtures in @pytest.mark.parametrize.
MIT License
55 stars 2 forks source link

ScopeMismatch with pytest 8.1.1 #15

Closed loqs closed 1 month ago

loqs commented 5 months ago

In relation to https://github.com/Backblaze/b2-sdk-python/issues/484 and coverting from from pytest-lazy-fixture to pytest-lazy-fixtures to achieve pytest 8 compatibility using https://github.com/Backblaze/b2-sdk-python
https://github.com/loqs/b2-sdk-python/commit/849831babe911bf1d9cb1eb7c1e64210188e497e nox -s test-3.11 produced the following errors

_______________________________________________________________ ERROR at setup of TestCache.test_save_bucket[in_memory_cache] ________________________________________________________________
[gw28] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture in_memory_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:23:  def in_memory_cache()
__________________________________________________________ ERROR at setup of TestCache.test_list_bucket_names_ids[in_memory_cache] ___________________________________________________________
[gw12] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture in_memory_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:23:  def in_memory_cache()
__________________________________________________________ ERROR at setup of TestCache.test_set_bucket_name_cache[in_memory_cache] ___________________________________________________________
[gw30] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture in_memory_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:23:  def in_memory_cache()
__________________________________________________________ ERROR at setup of TestCache.test_list_bucket_names_ids[auth_info_cache] ___________________________________________________________
[gw9] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture auth_info_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:28:  def auth_info_cache()
__________________________________________________ ERROR at setup of TestCache.test_get_bucket_id_or_none_from_bucket_name[in_memory_cache] __________________________________________________
[gw3] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture in_memory_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:23:  def in_memory_cache()
__________________________________________________________ ERROR at setup of TestCache.test_set_bucket_name_cache[auth_info_cache] ___________________________________________________________
[gw23] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture auth_info_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:28:  def auth_info_cache()
_______________________________________________________________ ERROR at setup of TestCache.test_save_bucket[auth_info_cache] ________________________________________________________________
[gw7] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture auth_info_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:28:  def auth_info_cache()
__________________________________________________ ERROR at setup of TestCache.test_get_bucket_name_or_none_from_bucket_id[in_memory_cache] __________________________________________________
[gw5] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture in_memory_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:23:  def in_memory_cache()
__________________________________________________ ERROR at setup of TestCache.test_get_bucket_id_or_none_from_bucket_name[auth_info_cache] __________________________________________________
[gw24] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture auth_info_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:28:  def auth_info_cache()
__________________________________________________ ERROR at setup of TestCache.test_get_bucket_name_or_none_from_bucket_id[auth_info_cache] __________________________________________________
[gw19] linux -- Python 3.11.8 /var/cache/github/b2-sdk-python/.nox/unit-3-11/bin/python
ScopeMismatch: You tried to access the function scoped fixture auth_info_cache with a class scoped request object, involved factories:
test/unit/test_cache.py:33:  def cache(request)
test/unit/test_cache.py:28:  def auth_info_cache()

Is this expected? If so any suggestions on how to resolve the failures?

dev-petrov commented 1 month ago

Are you sure that this error happens because of my lib?

I think, that this error is correct, because you're trying to access func level fixture in class level fixture.

loqs commented 1 month ago

I think, that this error is correct, because you're trying to access func level fixture in class level fixture.

Any thoughts on what else in https://github.com/loqs/b2-sdk-python/commit/849831babe911bf1d9cb1eb7c1e64210188e497e could be triggering the issue? Have I misunderstood that pytest.lazy_fixture can be replaced by pytest.lazy_fixtures?

dev-petrov commented 1 month ago

I do not know how the earlier one worked for you. Because it's the same if you just use a functional fixture in the class. It will be the same mistake. I suggest removing scope="class", then there will be no error. Alternatively, specify scope="class" for in_memory_cache and auth_info_cache fixtures.

dev-petrov commented 1 month ago

@loqs hi! Did you tried my suggestions?

loqs commented 1 month ago

I suggest removing scope="class", then there will be no error.

This worked. It also worked with pytest-lazy-fixture 3.5.7 unpatched on python 3.11 and patched for python 3.12 compatibility on 3.12. Would you consider it a latent bug that pytest-lazy-fixtures has detected?

Did you tried my suggestions?

Apologies for the slow response.

dev-petrov commented 1 month ago

Yeah, I think that was a bug. I don't know how it was working previously.

dev-petrov commented 1 month ago

@loqs may I close the issue?

dev-petrov commented 1 month ago

I'm closing an issue