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 lesteve:check-subclass-in-warns branch from 56528f0 to c7ab6a2 Dec 28, 2016
@coveralls
Copy link

@coveralls 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
Copy link

@coveralls 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 nicoddemus force-pushed the lesteve:check-subclass-in-warns branch from c7ab6a2 to 6173120 Dec 29, 2016
@nicoddemus
Copy link
Member

@nicoddemus 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
Author Contributor

Done

This comment has been minimized.

@nicoddemus

nicoddemus Dec 30, 2016
Member

Thanks!

@coveralls
Copy link

@coveralls 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 lesteve force-pushed the lesteve:check-subclass-in-warns branch from babbff4 to fa418c9 Dec 29, 2016
@lesteve
Copy link
Contributor Author

@lesteve 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

@coveralls 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
Copy link

@coveralls 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
Copy link

@coveralls 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
Author Contributor

Good point!

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

@coveralls 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
Copy link

@coveralls 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
Copy link
Member

@nicoddemus nicoddemus commented Jan 3, 2017

Thanks a lot @lesteve!

@nicoddemus nicoddemus merged commit 3494dd0 into pytest-dev:features Jan 3, 2017
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@lesteve
Copy link
Contributor Author

@lesteve lesteve commented Jan 3, 2017

Great, thanks a lot!

@lesteve lesteve deleted the lesteve:check-subclass-in-warns branch Jan 3, 2017
This was referenced Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants