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

pytest 8.1.0.dev gives TypeError: Warning message must be str #11954

Closed
pllim opened this issue Feb 8, 2024 · 2 comments · Fixed by #11959
Closed

pytest 8.1.0.dev gives TypeError: Warning message must be str #11954

pllim opened this issue Feb 8, 2024 · 2 comments · Fixed by #11959

Comments

@pllim
Copy link
Contributor

pllim commented Feb 8, 2024

Started noticing failures with pytest 8.1.0.dev171+g9454fc38d. I suspect it is caused by #11804 .

In astropy , we have a warning class that is a grandchild of Python built-in Warning class, defined as follows (don't ask me why, I am just the messenger):

class IllegalMinuteWarning(AstropyWarning):
    """
    Raised when a minute value is 60.

    Parameters
    ----------
    minute : int, float
    """

    def __init__(self, minute, alternativeactionstr=None):
        self.minute = minute
        self.alternativeactionstr = alternativeactionstr

    def __str__(self):
        message = (
            f"'minute' was found  to be '{self.minute}', which is not in range [0,60)."
        )
        if self.alternativeactionstr is not None:
            message += " " + self.alternativeactionstr
        return message

Works fine for years, until today. I think pytest type check is now too strict. Is this something you are able to relax a little on your end? Thanks!

Detailed log and more info here:

@RonnyPfannschmidt
Copy link
Member

That warning class doesn't implement a expected invariants

AKA it can't be used as category for a string message

I suppose it works by accident

If bug compatibility is easy enough we should support this while warning

@dhomeier
Copy link

dhomeier commented Feb 9, 2024

I'd agree that not accepting a Warning as reported in #11959 looks like a bug, but for numerical inputs this makes more sense, and would be fairly easy to fix on the Astropy side.

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 a pull request may close this issue.

3 participants