26424

How do I get Flake8 to work with F811 errors?

We're using flake8 to test our code, and we're using pytest with fixtures. The following code:

from staylists.tests.fixtures import fixture1 # noqa: F401 def test_case(fixture1): # noqa: F811 # Test goes here assert 1 == 1

Generates a lib/python/test.py:3:1: F811 redefinition of unused 'fixture1' from line 1 error during linting.

    <li><strong>Why does it ignore the noqa flag?</strong> </li> <li><strong>Is there a better way to avoid flagging this error?</strong> </li> </ul>

    Answer1:

    The F401 and F811 errors can be avoided by moving all fixtures into the <strong>conftest.py</strong> file. Pytest loads this file automatically and makes all fixtures inside available in all tests, even without explicit import statements.

    More discussion about the file can be found here: In py.test, what is the use of conftest.py files?

Recommend

  • ORA-04061: existing state of package body “PACKAGE.NAME” has been invalidated persists
  • Use pthreads in MinGW in Win7
  • Compile-errors: “creating array with negative size ('-0x00000000000000001')”, “assignment
  • mupdf for android: ndk-build problem (error: redefinition of typedef…)
  • “undefined symbol: SQLAllocEnv” error in Java [duplicate]
  • Intel c/c++ compiler: “could not locate executable icc” (and ecc)
  • Maven, ActionBarSherlock v4 and Roboguice v2 - How do I get it to build?
  • Could not find the following Boost libraries: boost_asio
  • /usr/bin/ld: error: cannot find -lboost_unit_test_framework
  • Objective-C : getting error on console while trying to display app on ipad device?
  • Einsum optimize fails for basic operation
  • Clion & CMake. How To Add Library (*.so)
  • Pytest/Allure - How to generate testcase description?
  • Importing pyplot in a Jupyter Notebook
  • Usage of local dart library
  • Unable to gem install nokogiri
  • Paramiko SSHException Channel Closed
  • Error while importing scikits.talkbox
  • What do I do with this error when I run tests in rails?
  • Doctrine2 inverse persistance not working in nested forms
  • HighCharts - Show tooltip on column where value is 0 or null
  • removing last 3 characters on a file (file extension)
  • triggering user space with kernel
  • Need code translation from VB to C#
  • PHP Listener Script for Paypal Webhooks
  • php script is parsing content from RTE (tt_news) but internal links are not appearing as speaking ur
  • How to get latest version of a artifact on Bintray using JSONP
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • pillow imaging ImportError
  • Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+
  • error importing numpy
  • Django simple Captcha “No module named fields” error
  • How to know when stdin is empty if it contains EOF?
  • Very simple C++ DLL that can be called from .net
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string