Skip to content

Added capture_stderr decorator to test_validate_docstrings #22543

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

Merged
merged 3 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pandas/tests/scripts/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import numpy as np
import pytest

from pandas.util.testing import capture_stderr


class GoodDocStrings(object):
"""
Expand Down Expand Up @@ -553,21 +555,25 @@ def _import_path(self, klass=None, func=None):

return base_path

@capture_stderr
def test_good_class(self):
assert validate_one(self._import_path( # noqa: F821
klass='GoodDocStrings')) == 0

@capture_stderr
@pytest.mark.parametrize("func", [
'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1',
'contains', 'mode'])
def test_good_functions(self, func):
assert validate_one(self._import_path( # noqa: F821
klass='GoodDocStrings', func=func)) == 0

@capture_stderr
def test_bad_class(self):
assert validate_one(self._import_path( # noqa: F821
klass='BadGenericDocStrings')) > 0

@capture_stderr
@pytest.mark.parametrize("func", [
'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method'])
def test_bad_generic_functions(self, func):
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def capture_stderr(f):
AssertionError: assert 'foo\n' == 'bar\n'
"""

@wraps(f)
@compat.wraps(f)
Copy link
Member Author

@WillAyd WillAyd Aug 30, 2018

Choose a reason for hiding this comment

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

Looks like wraps wasn't preserving the signature in Py27 which would cause this to choke when combined with a parametrized function. Simply switched to the function from compat for now - providing as reference in case anyone runs into a similar issue in the future

def wrapper(*args, **kwargs):
try:
sys.stderr = StringIO()
Expand Down