Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore Pyflakes errors ‘imported but unused’ in the ‘__init__.py’ file?

I split my tests across multiple Python files:

tests
├── __init__.py
├── test_apples.py
└── test_bananas.py.py

I import the tests in the ‘__init__.py’ file:

from test_apples import ApplesTest
from test_bananas import BananasTest

However running Pyflakes on the command-line:

pyflakes .

outputs the following errors:

tests/__init__.py:1: [E] PYFLAKES:'ApplesTest' imported but unused
tests/__init__.py:2: [E] PYFLAKES:'BananasTest' imported but unused
like image 310
Venkatesh Bachu Avatar asked Dec 08 '11 07:12

Venkatesh Bachu


3 Answers

To ignore all errors F401 (‘imported but unused’) in ‘__init__.py’ files, the option ‘per-file-ignores’ which has been available since version 3.7.0 of Flake8 (a better Pyflakes) is very convenient. It can be used on the command-line:

flake8 --per-file-ignores="__init__.py:F401" .

or in a configuration file (‘.flake8’, ‘setup.cfg’ or ‘tox.ini’):

[flake8]
per-file-ignores = __init__.py:F401
like image 132
Maggyero Avatar answered Oct 22 '22 02:10

Maggyero


Sometimes you have to skip a line. According to the current versions docs (flake8 2.4.1) The files that contain

# flake8: noqa

are skipped. This works, and # noga, # pyflakes.ignore not.

like image 11
horbor Avatar answered Oct 22 '22 01:10

horbor


In my version of PyFlakes (0.7.3), using __all__ works.

Additionally, to skip a line, you should add # noqa.

like image 10
dustinfarris Avatar answered Oct 22 '22 02:10

dustinfarris