Closed ravirahman closed 7 months ago
can confirm seeing the same issue in both 7.2.0 and 8.0.0
Thanks for bringing this to our attention, @ravirahman. I've added a ticket about this to an internal backlog, and it will be included in future prioritization passes.
cc @romainkomorndatadog
I'm gonna reopen this since there's a comment about pytest
7.2.0
, and also because I can't reproduce this naively with pytest
8.0.0
and Flask (which is my usual test "benchmark" repo).
I set up an environment with:
3.8.17
pytest
7.2.0
and 8.0.0
pytest-xdist
3.5.0
ddtrace
2.5.1
git@github.com:pallets/flask.git
) at commit 4df377cfbfc1d15e962a61c18920b22aebc9aa41
In both cases, I successfully ran tests with
DD_SERVICE=flask DD_ENV=itr-on pytest --ddtrace -n auto
So whatever's going on isn't strictly related to pytest
8.0.0
.
@ravirahman , are you only seeing this failure when you upgrade to 8.0.0
from 7.x
?
@jhilimirejc , are you seeing the same traceback, give or take?
INTERNALERROR> E File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/ddtrace/contrib/pytest/plugin.py", line 835, in pytest_ddtrace_get_item_module_name
INTERNALERROR> E return pytest_package_item.module.__name__
INTERNALERROR> E AttributeError: 'Package' object has no attribute 'module'
@ravirahman , it'd be helpful if you could also try without using pytest-xdist
, and if possible, how you're invoking pytest
(ie the full CLI).
@jhilimirejc more details from you would be very welcome as well.
https://github.com/pytest-dev/pytest/issues/11137 does look like a potentially related change here, though if that were the case, it seems like I should definitely see a failure with 8.0.0
, so I'll have to do some extra investigating.
There's a follow-up for me to have a default behavior for the module/suite/test naming hooks that doesn't cause exceptions (and if it does, that we just fail within CIVisibility
and yield
or return
properly).
I can reproduce the same failure with Starlette ( git@github.com:encode/starlette.git
) at 4355e6bc288e14dea9597ad9c9265c0f9cad33c0
, so @ravirahman , I don't think I need more from you at this point. Thanks for the report!
@jhilimirejc , if you could confirm whether you're seeing the same stacktrace with 7.2.0
, that'd be great. If it's a different trace, could you open a different issue with details?
@romainkomorndatadog -We are not using pytest-xdist. However we had our version pinned at 1.20.2 and saw the same error, we attempted to upgrade and continue to see the same issue regardless of ddtrace or pytest versions
[tool.poetry.dependencies] python = "^3.10" PyGithub = "^1.51" GitPython = "^3.1.41" pyyaml = "^6.0.1" requests = "^2.31.0" azure-graphrbac = "0.61.0" braceexpand = "^0.1.7" junitparser = "^2.8.0" tabulate = "^0.9.0"
[tool.poetry.dev-dependencies] awscli = "^1.29.5" cryptography = ">=39.0.2" google-api-python-client = "^2.65.0" google-auth-oauthlib = "^0.7.0" google-auth-httplib2 = "^0.1.0" oauth2client = "^4.1.3" pyOpenSSL = "^23.0.0" pytest = "^7.2.0" python-ldap = "^3.3.1" typing_extensions = "^3.7.4" slackclient = "2.5.0" gherkin-official = "^24.1.0" Jinja2 = "3.0.3" /ddtrace and cattrs locked to specific versions due to requiring a typing_extensions upgrade to work correctly ddtrace = "1.20.2" cattrs = "22.2.0" pre-commit = "^2.2.0" sphinx = "^2.4.1" sphinx-gherkindoc = "^3.6.3" pytest-repeat = "^0.9.1" pdbpp = "^0.10.2" pyotp = "^2.4.1" tenacity = "^8.0.0"
(upgraded ddtrace, cattrs & attrs along with typing_extensions- and even tried pytest at 8.0.0 and still come across same error)
while our version of pytest is careted - i've pinned it to 7.20.0 and also see the same output:
INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 272, in wrap_session INTERNALERROR> session.exitstatus = doit(config, session) or 0 INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 326, in _main INTERNALERROR> config.hook.pytest_runtestloop(session=session) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in call INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall INTERNALERROR> raise exception.with_traceback(exception.traceback) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 121, in _multicall INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr] INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/logging.py", line 796, in pytest_runtestloop INTERNALERROR> return (yield) # Run all the tests. INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall INTERNALERROR> res = hook_impl.function(args) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 351, in pytest_runtestloop INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in call INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 181, in _multicall INTERNALERROR> return outcome.get_result() INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_result.py", line 99, in get_result INTERNALERROR> raise exc.with_traceback(exc.traceback) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 87, in _multicall INTERNALERROR> next(wrapper_gen) # first yield INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/pytest/plugin.py", line 604, in pytest_runtest_protocol INTERNALERROR> test_module_span, module_is_package = _start_test_module_span(item) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/pytest/plugin.py", line 279, in _start_test_module_span INTERNALERROR> test_module_span.set_tag_str(test.MODULE, item.config.hook.pytest_ddtrace_get_item_module_name(item=item)) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in call INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall INTERNALERROR> raise exception.with_traceback(exception.traceback) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall INTERNALERROR> res = hook_impl.function(args) INTERNALERROR> File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/pytest/plugin.py", line 835, in pytest_ddtrace_get_item_module_name INTERNALERROR> return pytest_package_item.module.name INTERNALERROR> AttributeError: 'Package' object has no attribute 'module'
I put together a simple reproducer that can be found here: https://github.com/iherasymenko/ddtrace-8220-reproducer.
The key to trigger this error is to have a test file placed in a module.
As an update, I've got a WIP PR to support pytest 8.x
in #8357 , but 8.x
changes the order in which tests are processed, so I'm likely going to have to spend more time than I'd like refactoring tests so that they don't take order into account, so I'll probably have something mergeable on Wednesday (14 Feb).
@jhilimirejc , it would be very helpful if you could come up with a small repro case for Pytest 7.x
, since neither 6.x
nor 7.x
fail on @iherasymenko 's reproducer. (edited to fix "Python 7.x" and double-negative "neither doesn't fail").
And @iherasymenko , thank you so much for that repro case. Definitely saved me some time.
For visibility here, I just wrote https://github.com/DataDog/dd-trace-py/pull/8357#issuecomment-1943345575 to say I need to take on a bit of a deeper rewrite of our CIVisibility
service and pytest
integration so that the changes made to support version 8.0
aren't just a set of temporary patches.
It'll be a slower turnaround but the changes are also needed for other work we have scheduled around telemetry and log collection.
Looks like this landed in main and in 2.6. Could someone cut a release for 2.6?
As I mentioned in https://github.com/DataDog/dd-trace-py/pull/8357#issuecomment-1948460944 , I ended up merging a short-term fix that addresses the reproducible crashes I could find.
For this repo, over the past 24 hours, we've had 235 successful test sessions where the pytest
version is 8.0.0
or 8.0.1
, and 25k passed tests. That's a good omen even if it doesn't entirely rule out edge cases I missed.
@tamird , let me see when we can get 2.6
out.
Thanks for the fix @romainkomorndatadog. Our test suite is now all green with ddtrace 2.6.4 and pytest 8.0.1.
@tamird , I just released 2.6.4 and it passes the reproducer test.
(I wrote this hours ago and didn't hit the Comment button...)
@iherasymenko , thanks for confirming (and thanks again for the repro case :) ).
I didnt have a way to create a reproduction like @iherasymenko , sorry about that but can confirm that it's working now using 2.6.4 with pytest 8.0.1 also. thanks!
DDTrace is incompatible with pytest 8
Which version of dd-trace-py are you using?
2.5.1
Which version of pip are you using?
23.0.1
Which libraries and their versions are you using?
pytest 8.0.0
How can we reproduce your problem?
Run pytest with ddtrace and pytest 8
What is the result that you get?
What is the result that you expected?
My tests run without crashing