question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to address DeprecationWarning with Node.from_parent

See original GitHub issue

In jaraco/pytest-checkdocs#3, I started observing a warning in my projects.

.tox/python/lib/python3.8/site-packages/pytest_checkdocs.py:12
  /Users/jaraco/code/main/jaraco.util/.tox/python/lib/python3.8/site-packages/pytest_checkdocs.py:12: PytestDeprecationWarning: direct construction of CheckdocsItem has been deprecated, please use CheckdocsItem.from_parent
    return CheckdocsItem(path, parent) if path.basename == 'setup.py' else None

I see similar warnings in pytest-flake8 and pytest-black.

.tox/python/lib/python3.8/site-packages/pytest_flake8.py:65
  /Users/jaraco/code/main/pytest-checkdocs/.tox/python/lib/python3.8/site-packages/pytest_flake8.py:65: PytestDeprecationWarning: direct construction of Flake8Item has been deprecated, please use Flake8Item.from_parent
    return Flake8Item(

.tox/python/lib/python3.8/site-packages/pytest_black.py:26
  /Users/jaraco/code/main/pytest-checkdocs/.tox/python/lib/python3.8/site-packages/pytest_black.py:26: PytestDeprecationWarning: direct construction of BlackItem has been deprecated, please use BlackItem.from_parent
    return BlackItem(path, parent)

I’ve attempted to port this code to the new recommended format, but I haven’t been able to figure out the syntax.

I tried this patch:

diff --git a/pytest_checkdocs.py b/pytest_checkdocs.py
index 970cf26..9db4a0a 100644
--- a/pytest_checkdocs.py
+++ b/pytest_checkdocs.py
@@ -9,7 +9,11 @@ from more_itertools import first
 
 def pytest_collect_file(path, parent):
     """Filter files down to which ones should be checked."""
-    return CheckdocsItem(path, parent) if path.basename == 'setup.py' else None
+    return (
+        CheckdocsItem.from_parent(parent, name=path)
+        if path.basename == 'setup.py'
+        else None
+    )
 
 
 class CheckdocsItem(pytest.Item, pytest.File):

But that gives me an error:

_____________________________________________________________________ ERROR collecting test session ______________________________________________________________________
.tox/python/lib/python3.8/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
.tox/python/lib/python3.8/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
.tox/python/lib/python3.8/site-packages/pluggy/manager.py:84: in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
pytest_checkdocs.py:13: in pytest_collect_file
    CheckdocsItem.from_parent(parent, name=path)
E   TypeError: from_parent() got an unexpected keyword argument 'name'

I don’t understand how from_parent could have an unexpected keyword argument when it accepts all keyword arguments.

What is the proper way to implement a hook in pytest_collect_file to construct a Node/Item?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jaracocommented, Mar 15, 2020

pytest-checkdocs has a structural error by inheriting from both file and item

ugh. I’m not sure where I got that pattern from - probably from pytest-flake8.

0reactions
Zac-HDcommented, Jun 9, 2020

If it’s working, I guess that’s something 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js deprecation warning and better developer experiences
Let's talk about v7 and the better developer experience it brings, discuss the Node.js deprecation warning and more.
Read more >
Deprecations and Removals — pytest documentation
Instance , and importing it emits a deprecation warning. This will be removed in pytest 8. fspath argument for Node constructors replaced with...
Read more >
Deprication warnings from Pytest · Issue #139 - GitHub
Use new Node.from_parent constructor when available #152 ... Fixing CI failures due to a deprecation warning in nbval facebookresearch/hydra#835.
Read more >
(node: 15702) How to remove DeprecationWarning on Node.js?
I am getting a deprecation warning message on my shell while using Node.js. It started showing up in the middle of my project, ......
Read more >
Breaking Changes | Electron
Breaking changes will be documented here, and deprecation warnings added to JS code where possible, at least one major version before the change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found