pytest-dev / pytest-cov

Coverage plugin for pytest.
MIT License
1.72k stars 211 forks source link

DeprecationWarning: currentThread() is deprecated, use current_thread() instead #609

Closed nbro10 closed 11 months ago

nbro10 commented 11 months ago

Summary

I'm getting the following error/warning, when attempting to run pytest with pytest-cov, in a Python 3.11.2 environment

DeprecationWarning: currentThread() is deprecated, use current_thread() instead

Command: poetry run pytest tests --cov=my_package --verbose --durations=15 --capture=no --numprocesses=auto --strict-markers --no-success-flaky-report -p no:unraisableexception

Full logs

``` Traceback (most recent call last): File "/path/to/my/virtual/env/bin/pytest", line 8, in sys.exit(console_main()) ^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 185, in console_main code = main() ^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 143, in main config = _prepareconfig(args, plugins) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig config = pluginmanager.hook.pytest_cmdline_parse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_callers.py", line 130, in _multicall teardown[0].send(outcome) File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse config: Config = outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse self.parse(args) File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1283, in parse self._preparse(args, addopts=addopts) File "/path/to/my/virtual/env/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1191, in _preparse self.hook.pytest_load_initial_conftests( File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_callers.py", line 152, in _multicall return outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/path/to/my/virtual/env/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pytest_cov/plugin.py", line 126, in pytest_load_initial_conftests plugin = CovPlugin(options, early_config.pluginmanager) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pytest_cov/plugin.py", line 175, in __init__ self.start(engine.DistMaster) File "/path/to/my/virtual/env/lib/python3.11/site-packages/pytest_cov/plugin.py", line 199, in start self.cov_controller.start() File "/path/to/my/virtual/env/lib/python3.11/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper return meth(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/pytest_cov/engine.py", line 267, in start self.cov.start() File "/path/to/my/virtual/env/lib/python3.11/site-packages/coverage/control.py", line 549, in start self._collector.start() File "/path/to/my/virtual/env/lib/python3.11/site-packages/coverage/collector.py", line 306, in start fn = self._start_tracer() ^^^^^^^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/coverage/collector.py", line 264, in _start_tracer fn = tracer.start() ^^^^^^^^^^^^^^ File "/path/to/my/virtual/env/lib/python3.11/site-packages/coverage/pytracer.py", line 223, in start self.thread = self.threading.currentThread() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/me/.pyenv/versions/3.11.2/lib/python3.11/threading.py", line 1465, in currentThread warnings.warn('currentThread() is deprecated, use current_thread() instead', DeprecationWarning: currentThread() is deprecated, use current_thread() instead ```

Expected vs actual result

Reproducer

Versions

Python 3.11.2 (or 3.11.5) pytest 6.2.5 pytest-cov 2.11.1 coverage 5.5 (with extra toml)

Config

pyproject.toml

[tool.pytest.ini_options]
minversion = "6.0"
filterwarnings = [
   "some ignores"
]
xfail_strict = true
norecursedirs = ["build", "dist", "docs", "requirements"]
log_level = "DEBUG"
log_format = "%(levelname)s %(message)s (%(name)s:%(lineno)s)"
log_date_format = "%Y-%m-%d %H:%M:%S"
console_output_style = "classic"
markers = ["slow: mark a test as slow"]
addopts = "--verbose --durations=15 --capture=no --numprocesses=auto --strict-markers --no-success-flaky-report -p no:unraisableexception"

[tool.coverage]
run.omit = ["*scripts*", "*tests*"]
report.show_missing = true
report.skip_covered = true
report.fail_under = 100
report.exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]

Code

Just create e.g. a test package tests with a test file test_something.py, with a dummy test function

nbro10 commented 11 months ago

Updating coverage to version 7.3.1 seems to solve the issue. In any case, I'm reporting it here, just in case someone else faces this issue too.

Maybe a developer can explain more in detail why this is happening and why this solves the issue?!