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.warns checks for subclass relationship rather than class equality #2166

Merged
merged 6 commits into from
Jan 3, 2017

Conversation

lesteve
Copy link
Contributor

@lesteve lesteve commented Dec 28, 2016

This makes it more similar to pytest.raises. Fix #2151.

@lesteve lesteve force-pushed the check-subclass-in-warns branch from 56528f0 to c7ab6a2 Compare December 28, 2016 21:52
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 92.693% when pulling c7ab6a2 on lesteve:check-subclass-in-warns into 669332b on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 92.693% when pulling c7ab6a2 on lesteve:check-subclass-in-warns into 669332b on pytest-dev:features.

@nicoddemus nicoddemus force-pushed the check-subclass-in-warns branch from c7ab6a2 to 6173120 Compare December 29, 2016 00:43
@nicoddemus
Copy link
Member

Thanks @lesteve for the PR, appreciate it!

I rebased your branch into the latest features and pushed to your fork, hope you don't mind.

@@ -238,6 +238,16 @@ def test_record_only(self):
assert str(record[0].message) == "user"
assert str(record[1].message) == "runtime"

def test_record_by_subclass(self):
Copy link
Member

Choose a reason for hiding this comment

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

Could you please also add a test which checks for warning subclasses when the user passes more than one warning to pytest.warns? For example:

class Warn1(UserWarning): pass
class Warn2(RuntimeWarning): pass

with pytest.warns((UserWarning, RuntimeWarning)):
   warnings.warn("w1", Warn1)
   warnings.warn("w2", Warn2)

assert len(record) == 2
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.689% when pulling 6173120 on lesteve:check-subclass-in-warns into 964ccb9 on pytest-dev:features.

@lesteve lesteve force-pushed the check-subclass-in-warns branch from babbff4 to fa418c9 Compare December 29, 2016 08:38
@lesteve
Copy link
Contributor Author

lesteve commented Dec 29, 2016

I rebased your branch into the latest features and pushed to your fork, hope you don't mind.

Not at all, I think this is a really nice recent addition in GitHub that maintainers can push into PR branches!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.689% when pulling fa418c9 on lesteve:check-subclass-in-warns into 964ccb9 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.689% when pulling fa418c9 on lesteve:check-subclass-in-warns into 964ccb9 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.689% when pulling ae4a5be on lesteve:check-subclass-in-warns into 964ccb9 on pytest-dev:features.

@@ -238,6 +238,16 @@ def test_record_only(self):
assert str(record[0].message) == "user"
assert str(record[1].message) == "runtime"

def test_record_by_subclass(self):
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@@ -216,7 +216,8 @@ def __exit__(self, *exc_info):
# only check if we're not currently handling an exception
if all(a is None for a in exc_info):
if self.expected_warning is not None:
if not any(r.category in self.expected_warning for r in self):
if not any(issubclass(r.category, exp_warning) for
Copy link
Member

Choose a reason for hiding this comment

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

lets use issubclass with the propper classinfo support here, no need for own loops, please check the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

@lesteve lesteve force-pushed the check-subclass-in-warns branch from ae4a5be to 0229896 Compare January 3, 2017 11:06
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.704% when pulling 0229896 on lesteve:check-subclass-in-warns into 8f14501 on pytest-dev:features.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.704% when pulling 1f6a33b on lesteve:check-subclass-in-warns into 8f14501 on pytest-dev:features.

@nicoddemus
Copy link
Member

Thanks a lot @lesteve!

@nicoddemus nicoddemus merged commit 3494dd0 into pytest-dev:features Jan 3, 2017
@lesteve
Copy link
Contributor Author

lesteve commented Jan 3, 2017

Great, thanks a lot!

This was referenced Mar 6, 2018
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.

4 participants