tholo / pytest-flake8

pytest plugin to run flake8
Other
117 stars 47 forks source link

Use of standard flake8 configuration locations #22

Open schtibe opened 7 years ago

schtibe commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

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

Peque commented 6 years ago

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 commented 6 years ago

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 commented 5 years ago

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

bobhy commented 4 years ago

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 commented 4 years ago

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

bobhy commented 4 years ago

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 commented 4 years ago

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: