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

Projects
None yet
4 participants
@lesteve
Contributor

lesteve commented Dec 28, 2016

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

@coveralls

This comment has been minimized.

coveralls commented Dec 28, 2016

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

This comment has been minimized.

coveralls commented Dec 28, 2016

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

This comment has been minimized.

Member

nicoddemus commented Dec 29, 2016

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):

This comment has been minimized.

@nicoddemus

nicoddemus Dec 29, 2016

Member

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
...

This comment has been minimized.

@lesteve

lesteve Dec 29, 2016

Contributor

Done

This comment has been minimized.

@nicoddemus

nicoddemus Dec 30, 2016

Member

Thanks!

@coveralls

This comment has been minimized.

coveralls commented Dec 29, 2016

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

coveralls commented Dec 29, 2016

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

This comment has been minimized.

coveralls commented Dec 29, 2016

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

This comment has been minimized.

coveralls commented Dec 29, 2016

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):

This comment has been minimized.

@nicoddemus

nicoddemus Dec 30, 2016

Member

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

This comment has been minimized.

@RonnyPfannschmidt

RonnyPfannschmidt Jan 3, 2017

Member

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

This comment has been minimized.

@lesteve

lesteve Jan 3, 2017

Contributor

Good point!

@coveralls

This comment has been minimized.

coveralls commented Jan 3, 2017

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

This comment has been minimized.

coveralls commented Jan 3, 2017

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

This comment has been minimized.

Member

nicoddemus commented Jan 3, 2017

Thanks a lot @lesteve!

@nicoddemus nicoddemus merged commit 3494dd0 into pytest-dev:features Jan 3, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@lesteve

This comment has been minimized.

Contributor

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