Skip to content

Make a code check which bans imports of fixtures in tests #30914

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

Closed
MarcoGorelli opened this issue Jan 11, 2020 · 5 comments · Fixed by #33664
Closed

Make a code check which bans imports of fixtures in tests #30914

MarcoGorelli opened this issue Jan 11, 2020 · 5 comments · Fixed by #33664
Assignees
Labels
Code Style Code style, linting, code_checks Testing pandas testing functions or related to the test suite
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Jan 11, 2020

xref #30894 (comment)

Example: writing

from pandas.conftest import ALL_EA_INT_DTYPES

in a test file should be disallowed because there exists the fixture any_nullable_int_dtype

@jbrockmendel jbrockmendel added the Code Style Code style, linting, code_checks label Feb 25, 2020
@SaturnFromTitan
Copy link
Contributor

take

@jorisvandenbossche
Copy link
Member

There are some useful things that are imported from conftest.py that cannot be converted to a fixture. So "fixing" this should first discuss what to do instead (or where to move those) ?

@SaturnFromTitan
Copy link
Contributor

Good point @jorisvandenbossche I'll check the current violations and make a proposal here.

@SaturnFromTitan
Copy link
Contributor

SaturnFromTitan commented Mar 24, 2020

Alright, so there are basically three types of cases:

  1. indices_dict is imported to create a more specific fixture. I submitted two PRs to resolve these cases as they can easily be replaced with using indices
  2. _get_cython_table_params is imported. I suggest moving it to pandas._testing. It's not used for to create fixtures anyways, so it doesn't really make sense to have it in conftest.py
  3. Any of these dtype constants are imported. Not sure what to do here... We have to move them somewhere else, but I don't know what's a good location. Maybe create a pandas._dtypes.py?

Wdyt @jreback @simonjayhawkins @jorisvandenbossche?

@simonjayhawkins
Copy link
Member

for 1 the two PRs lgtm.

agree with 2.

for 3 could have the constants in a separate module as suggested (like token.py — Constants used with Python parse trees) and then import into testing.py (like tokenize.py — Tokenizer for Python source - All constants from the token module are also exported from tokenize) and then we could do say tm.UNSIGNED_INT_DTYPES

jreback pushed a commit that referenced this issue Mar 29, 2020
* [#30914] Make a code check which bans imports of fixtures in tests

* using indices fixture instead of duplicative index fixture

* calling 'indices' fixture as 'index'

* Revert "calling 'indices' fixture as 'index'"

This reverts commit 1eba26d.

* using string_index fixture instead of @pytest.mark.parametrize(indices, [string], indirect=True)

* Revert "using string_index fixture instead of @pytest.mark.parametrize(indices, [string], indirect=True)"

This reverts commit 2a3e611.
@simonjayhawkins simonjayhawkins added the Testing pandas testing functions or related to the test suite label Apr 20, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants