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

7.1.0 - ImportError with pytest-cases #9762

Closed
flo-pasquier opened this issue Mar 14, 2022 · 7 comments
Closed

7.1.0 - ImportError with pytest-cases #9762

flo-pasquier opened this issue Mar 14, 2022 · 7 comments

Comments

@flo-pasquier
Copy link

flo-pasquier commented Mar 14, 2022

Hi team,

  • trying to run a test suite (FastAPI) in a container
    RUN pip3 install --no-cache-dir responses pytest-7.0.1 pytest-asyncio pytest_cases pytest-cov httpx asgi-lifespan starlette ENTRYPOINT ["pytest","-vv","--cov=.","tests"]

  • things are working fine in 7.0.1

  • execution is failing in 7.1.0

Traceback (most recent call last):
  File "[/usr/local/lib/python3.10/runpy.py]()", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "[/usr/local/lib/python3.10/runpy.py]()", line 86, in _run_code
    exec(code, run_globals)
  File "[/usr/local/lib/python3.10/site-packages/debugpy/__main__.py]()", line 45, in <module>
    cli.main()
  File "[/usr/local/lib/python3.10/site-packages/debugpy/server/cli.py]()", line 444, in main
    run()
  File "[/usr/local/lib/python3.10/site-packages/debugpy/server/cli.py]()", line 331, in run_module
    run_module_as_main(target_as_str, alter_argv=True)
  File "[/usr/local/lib/python3.10/runpy.py]()", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "[/usr/local/lib/python3.10/runpy.py]()", line 86, in _run_code
    exec(code, run_globals)
  File "[/usr/local/lib/python3.10/site-packages/pytest/__main__.py]()", line 5, in <module>
    raise SystemExit(pytest.console_main())
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 187, in console_main
    code = main()
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 145, in main
    config = _prepareconfig(args, plugins)
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py]()", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_manager.py]()", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_callers.py]()", line 55, in _multicall
    gen.send(outcome)
  File "[/usr/local/lib/python3.10/site-packages/_pytest/helpconfig.py]()", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_result.py]()", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_callers.py]()", line 39, in _multicall
    res = hook_impl.function(*args)
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 1020, in pytest_cmdline_parse
    self.parse(args)
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 1308, in parse
    self._preparse(args, addopts=addopts)
  File "[/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py]()", line 1191, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "[/usr/local/lib/python3.10/site-packages/pluggy/_manager.py]()", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "[/usr/local/lib/python3.10/importlib/metadata/__init__.py]()", line 162, in load
    module = import_module(match.group('module'))
  File "[/usr/local/lib/python3.10/importlib/__init__.py]()", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
 File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "[/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py]()", line 168, in exec_module
    exec(co, module.__dict__)
  File "[/usr/local/lib/python3.10/site-packages/pytest_cases/__init__.py]()", line 8, in <module>
    from .fixture_core1_unions import fixture_union, NOT_USED, unpack_fixture, ignore_unused
  File "[/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py]()", line 168, in exec_module
    exec(co, module.__dict__)
  File "[/usr/local/lib/python3.10/site-packages/pytest_cases/fixture_core1_unions.py]()", line 26, in <module>
    from .common_pytest import get_fixture_name, is_marked_parameter_value, get_marked_parameter_values, pytest_fixture, \
  File "[/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py]()", line 168, in exec_module
    exec(co, module.__dict__)
  File "[/usr/local/lib/python3.10/site-packages/pytest_cases/common_pytest.py]()", line 557, in <module>
    from _pytest.python import _idval  # noqa
ImportError: cannot import name '_idval' from '_pytest.python' ([/usr/local/lib/python3.10/site-packages/_pytest/python.py]())

Thanks!!


(Edited by @The-Compiler to use triple-backticks for a more readable log)

@RonnyPfannschmidt
Copy link
Member

This is a issue with pytest-cases

It's importing pytest internal functions and seems to be affected by a recent refactoring

Cc @smarie

@smarie
Copy link
Contributor

smarie commented Mar 14, 2022

indeed. i'll have a look

@smarie
Copy link
Contributor

smarie commented Mar 14, 2022

This is related with the fact that pytest-cases needs to reproduce the internal behaviour of pytest concerning ids, so it imports _idval:

https://github.com/smarie/python-pytest-cases/blob/501f9fbca05f1e616fa3f9e8ead060f1d5896071/src/pytest_cases/common_pytest.py#L557-L605

I'll check if _idval simply has moved or if a more impactful change has been done

@smarie
Copy link
Contributor

smarie commented Mar 14, 2022

This is the change that caused the issue : #9547

I now have to understand how to use this new class

@smarie
Copy link
Contributor

smarie commented Mar 14, 2022

It seems from this line https://github.com/pytest-dev/pytest/pull/9547/files#diff-8c7f0a3f8b92ae0916642f3b256b96789070d3637e6d7ea4dfe1f7b3e2af3fe3L289

that using IdMaker([], [], None, None, None, None, None)._idval will do the trick.

smarie pushed a commit to smarie/python-pytest-cases that referenced this issue Mar 14, 2022
smarie added a commit to smarie/python-pytest-cases that referenced this issue Mar 14, 2022
* Removed erroneous copyright headers

* Fixed `ImportError` when using `pytest 7.1`. Fixed #264 and pytest-dev/pytest#9762

* Added two easy flake8 fixes

Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
@smarie
Copy link
Contributor

smarie commented Mar 14, 2022

Fixed in pytest-cases 3.6.10.
Thanks for reporting !

@The-Compiler
Copy link
Member

Thanks @smarie for the quick fix!

@The-Compiler The-Compiler changed the title 7.1.0 - Can't load/execute tests anymore 7.1.0 - ImportError with pytest-cases Mar 14, 2022
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

4 participants