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

turn RecordedWarning into a namedtuple #2014

Merged

Conversation

RonnyPfannschmidt
Copy link
Member

fixes #2013

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.005%) to 92.844% when pulling ce66923 on RonnyPfannschmidt:warning-record-namedtuple into c0719a5 on pytest-dev:master.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than a CHANGELOG message.

Please be descriptive of the change, specially that RecordedWarning is now a namedtuple so if someone gets tripped by it at least there's a clear warning, something like:

  • RecordedWarning objects (returned by pytest.warns and recwarn fixture) are now namedtuples so they have a better default string representation when displayed in assertion messages (#number).

self.file = file
self.line = line

RecordedWarning = namedtuple('RecordedWarning', (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small side effect here, RecordedWarning attributes are now read-only.

The docs themselves have this to say about it:

Each recorded warning has the attributes message, category, filename, lineno, file, and line. The category is the class of the warning. The message is the warning itself; calling str(message) will return the actual message of the warning.

IMO your change is good and I doubt there are people writing to the attributes, but I thought I would mention this anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this also means this should go to features

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel this way, perhaps you should just add a __repr__ method then? This would solve the issue and could go into master.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, i just reduced the amount of boilerplate to maintain, i wont add it back to add even more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, no problem

@RonnyPfannschmidt RonnyPfannschmidt changed the base branch from master to features October 24, 2016 13:22
@nicoddemus nicoddemus merged commit d49e9e5 into pytest-dev:features Nov 1, 2016
@nicoddemus
Copy link
Member

Sorry for not merging earlier, completely missed the new commits!

@RonnyPfannschmidt RonnyPfannschmidt deleted the warning-record-namedtuple branch November 2, 2016 07:59
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.

3 participants