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

Use of standard flake8 configuration locations #22

Open
schtibe opened this issue Apr 3, 2017 · 9 comments
Open

Use of standard flake8 configuration locations #22

schtibe opened this issue Apr 3, 2017 · 9 comments
Labels

Comments

@schtibe
Copy link

schtibe commented Apr 3, 2017

According to the docs, flake8 can handle different locations of configuration: setup.cfg, tox.ini, or .flake8.
Sadly these config files are not considered by pytest-flake8 for some reason. Is there a reason or could this be fixed?

If it read the default locations, it would be possible to configure flake8 in one place and use that configuration for both cli invocation and via pytest.

@dbrgn
Copy link

dbrgn commented Jun 26, 2017

Yes, that would be great. I need to configure the builtins option but can't, because the plugin doesn't support that parameter yet.

@tholo
Copy link
Owner

tholo commented Oct 23, 2017

I think this might have been corrected with the (now merged) #21 ?

@tholo tholo added the question label Oct 24, 2017
@Peque
Copy link

Peque commented Mar 22, 2018

I have my flake8 configuration written in tox.ini and it seems to work fine (i.e. both when calling flake8 from the terminal and when running pytest --flake8).

@khink
Copy link

khink commented Jul 27, 2018

Maybe this is a separate story, but:

When i put my pytest config in tox.ini, the flake8 settings are parsed. That's good.

However my editor's linter (SublimeText 3 Flaske8Lint plugin, https://github.com/dreadatour/Flake8Lint/) doesn't recognize the pytest-specific .ini markup:

# This part is parsed by Flake8Lint (and flake8 in general)
[flake8]
# copy manually from pytest:flake8-max-line-length
max-line-length = 119
# copy manually from pytest:flake8-ignore
ignore = D100,D101,D102,D103,D204,E731


# This part is parsed by pytest-flake8
[pytest]
DJANGO_SETTINGS_MODULE = settings.development
testpaths = website
norecursedirs = migrations
pep8maxlinelength = 119
mccabe-complexity =
    *.py 6
isort_ignore =
    docs/conf.py
    *migrations/*.py

flake8-max-line-length = 119
flake8-ignore =
# missing docstrings
    D100
    D100
    D101
    D102
    D103
# blank lines after docstrings
    D204
# do not assign a lambda expression, use a def
    E731

Because pytest-flake8 has its own variable names (flake8-max-line-length, flake8-ignore) and format, flake8 doesn't recognize these.

Did anyone else encounter this?

@jason-curtis
Copy link

@khink I'm seeing this too. The issue is less about what files are used, and more about what the configuration parameters are. It appears that all of the standard flake8 configuration settings are ignored when using pytest-flake8. I'm not sure why this is happening.

I'm experiencing it with python 3.6, flake8==3.7.7 and pytest-flake8==1.0.4. If I put ignores in tox.ini or setup.cfg within a [flake8] section using the ignore key (or the max_line_length key), they are respected when I run flake8 . but not when I run pytest (which has been configured with the --flake8 plugin in setup.cfg).

I would also support removing the plugin-specific parameters and just using the regular flake8 configuration files and settings instead.

jwodder added a commit to jwodder/pyrepo that referenced this issue Mar 13, 2020
pytest-flake8 doesn't properly honor [flake8] configuration in tox.ini (See
tholo/pytest-flake8#22), and, really, what do I need the plugin for?
@bobhy
Copy link

bobhy commented Apr 24, 2020

It seems that pytest-flake8 is ignoring flake8's excludes option now. I'm looking into fixing this once and for all by having the plugin use flake8 native config. In the meantime, dear reader, please provide your use case for flake8 settings needing to be different during a test run than they are when running flake8 from CLI or your IDE? I might have to also add some overrides...

@jason-curtis
Copy link

using native config is exactly what I would want to see! No test-specific overrides needed.

@bobhy
Copy link

bobhy commented Apr 25, 2020

Some further research. It looks like pytest-flake8 does use [flake8] settings, e.g ignores =, but only if you do not define the corresponding [tool:pytest] flake8-ignores =. This makes sense. But it took a recent checkin here to make ignores work. [flake8] excludes = also does not work when invoked pytest-flake8, and pytest-flake8 does not recognize flake8-excludes, probably the same issue. There's probably a small code fix and a doc fix needed to put it to rest forever. But what the fix is depends on whether someone has a good use case for needing overrides.

@bobhy
Copy link

bobhy commented Apr 27, 2020

OK, I have a V2 implementation of the plugin working (for n=1 project), and will soon be issuing a PR for it after I get some tests implemented..

In the meantime, you can install it from: https://github.com/bobhy/pytest-flake8, be sure to checkout branch use_flake8_config. It worked for me with flake8 v3.7 and v3.8, which broke the plugin api again.

V2 deprecates --flake8-ignores, --flake8-max-line-length and friends and instead abides by flake8 config file, mostly. So review your flake8 config file before trying this.

flake8 config drive this plugin with 2 exceptions:

  • Plugin accepts --flake8-show-source and --flake8-statistics on command line and in pytest config (though these are not working yet)
  • Plugin discovers files offered by pytest, but then skips them if they match a flake8 excluderule. This is a pytest plugin after all, its file discovery ought to count for something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants