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

TST: Change class-based auto-use setup to fixtures #21575

Closed
TomAugspurger opened this issue Jun 21, 2018 · 2 comments
Closed

TST: Change class-based auto-use setup to fixtures #21575

TomAugspurger opened this issue Jun 21, 2018 · 2 comments
Labels
Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite

Comments

@TomAugspurger
Copy link
Contributor

In #19535 we're excluding data test files from the distribution, which required some changes.

The hardest tests to update were the IO ones that read in a bunch of files in setup and set them as attributes on self.

In the PR, I changed these setup / teardown methods to be yield-base autouse yield methods. See https://github.com/pandas-dev/pandas/pull/19535/files#diff-8cfd1704100c1e13de1bac288482b344R41 for an example.

Ideally we would change the tests to accept the file / parsed object as a fixture, rather than accessing it off self.

The hard part is generating fixtures dynamically, e.g. one fixture per CSV in this directory. We can accomplish that with pytest_generate_tests: https://github.com/pandas-dev/pandas/pull/19535/files#diff-3f782eafb799811bd5516f328411418dR31

@TomAugspurger TomAugspurger added Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite labels Jun 21, 2018
@TomAugspurger TomAugspurger added this to the Next Major Release milestone Jun 21, 2018
@TomAugspurger
Copy link
Contributor Author

In #19535, we decided that auto-generating the fixtures with pytest_generate_tests is perhaps a bit too magical. Wherever possible, it'd be better to just explicitly write out the fixtures, e.g. like

@pytest.fixture(params=[
    'chinese_utf-16.html',
    'chinese_utf-32.html',
    'chinese_utf-8.html',
    'letz_latin1.html',
])
def html_encoding_file(request, datapath):
    """Parametrized fixture for HTML encoding test filenames."""
    return datapath('io', 'data', 'html_encoding', request.param)

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@mroeschke
Copy link
Member

I don't seem many old style def setup_* methods anymore in the test suite (especially related to IO functionality), so I think we can close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

2 participants