DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
552 stars 414 forks source link

pytest-bdd integration fails after module __version__ was removed in 6.1.0 #5404

Closed judgeaxl closed 1 year ago

judgeaxl commented 1 year ago

Summary of problem

When using pytest-bdd 6.1.0 or higher, the ddtrace integration fails to find the pytest-bdd version.

The version property was removed from pytest-bdd in 6.1.0 in this commit pytest-dev/pytest-bdd@6f95c5cacdafc954b8d60d6fcf93227230f2623a

Which version of dd-trace-py are you using?

1.10.1

Which version of pip are you using?

22.2.2

Which libraries and their versions are you using?

`pip freeze` ddtrace==1.10.1 pytest-bdd==6.1.1

How can we reproduce your problem?

Use pytest-bdd with a version higher than 6.1.0 together with ddtrace

Reverting to pytest-bdd 6.0.1 removes the problem

What is the result that you get?

Running tests fail with:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/ddtrace/contrib/pytest_bdd/plugin.py", line 30, in pytest_sessionstart
INTERNALERROR>     session.config.pluginmanager.register(_PytestBddPlugin(), "_datadog-pytest-bdd")
INTERNALERROR>   File "/home/axl/.local/share/virtualenvs/myproj-He54P3U2/lib/python3.10/site-packages/ddtrace/contrib/pytest_bdd/plugin.py", line 37, in __init__
INTERNALERROR>     self.framework_version = pytest_bdd.__version__
INTERNALERROR> AttributeError: module 'pytest_bdd' has no attribute '__version__'

What is the result that you expected?

No errors

judgeaxl commented 1 year ago

I found a solution in importlib.metadata

import importlib.metadata
version = importlib.metadata.version("pytest-bdd")
judgeaxl commented 1 year ago

I started on a PR for this, but I'm having trouble getting the testing environment to work in WSL2. Docker complains about ports not being free and riot testing fails in multiple ways. Perhaps someone who's got the environment up and running already can grab those two lines faster than I get this to work.

majorgreys commented 1 year ago

This is a duplicate of #4492. However, the library documentation does not state the version support for this integration. I will fix that and then we would need to work on adding support for newer versions of pytest-bdd.