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

Handle pytest 5.4 deprecation to use Node.from_parent #27

Closed

Conversation

jacebrowning
Copy link
Contributor

@jacebrowning jacebrowning commented Mar 28, 2020

Fixes #26
Depends on #25


In order to release this, I believe pytest-describe will need to officially drop support for pytest<5.4, which will in turn require dropping support for python<3.5.


To use this patch in your Poetry project, add the following to pyproject.toml:

[tool.poetry.dev-dependencies]

pytest-describe = { git = "https://github.com/jacebrowning/pytest-describe", branch = "pytest-5.4-support" } 

@Cito
Copy link
Member

Cito commented Mar 28, 2020

Thank you! Dropping support for Python 2 and Pytest < 5.4 would be even harsher than what I did in #25 though.

@jacebrowning
Copy link
Contributor Author

I wasn't totally sure when Node.from_parent() was introduced, but its introduction sets the minimum pytest version unless we want to get clever by checking for the existence of the method.

@Cito
Copy link
Member

Cito commented Mar 28, 2020

Maybe "use from_parent() except AttributeError: old way" will work?

@jacebrowning
Copy link
Contributor Author

There would also need to be changes to DescribeBlock.__init__(). Given that this warning only shows up with pytest>=5.4, it seems acceptable to me that the fix would require pytest>=5.4.

@Cito
Copy link
Member

Cito commented Mar 28, 2020

Ok, looked into this a bit more. How about this:

Remove the __init__ method alltogether, and create the following from_parent method instead:

    @classmethod
    def from_parent(cls, parent, obj):
        name = obj.__name__
        try:
            from_parent_super = super(DescribeBlock, cls).from_parent
        except AttributeError:  # PyTest < 5.4
            self = cls(name, parent)
        else:
            self = from_parent_super(parent, name=name)
        self._name = getattr(obj, '_mangled_name', name)
        self.funcobj = obj
        return self

Then, in pytest_pycollect_makeitem just return DescribeBlock.from_parent(collector, obj).

This works for me with all supported versions in #25.

Eventually, we should of course desupport the legacy Python and Pytest versions. But for now, I think it would be nice to have a version that is a bit more backward compatible.

@jacebrowning
Copy link
Contributor Author

Thanks for looking into the API a bit more!

Maybe we should let @ropez decide? If they have limited bandwidth, perhaps trying to support anything other than the latest version of pytest puts too much on their plate? Dropping support for legacy Python also simplifies the build matrix and allows us to drop the legacy super() syntax.

@Cito
Copy link
Member

Cito commented Mar 29, 2020

Even then, in order to test libraries that still need to support a broad range of Python versions, it would be nice to publish one last official release that supports that broad version range, and only then remove the Python 2 and older Pytest support, simplify the code for Python 3, and maybe release that as version 1.0 or so. We must not forget to adapt "install_requires" and the classifiers in setup.py when doing that.

@Cito
Copy link
Member

Cito commented Apr 21, 2020

This has now been solved in with the alternative fix in 453aa90 that also provides backward compatibility, so we can close this now.

@Cito Cito closed this Apr 21, 2020
@jacebrowning jacebrowning deleted the pytest-5.4-support branch April 21, 2020 13:46
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

Successfully merging this pull request may close these issues.

PytestDeprecationWarning regarding DescribeBlock with pytest 5.4
2 participants