0

I've set up Syntastic in Vim for Python development. Its been fantastic so far, but when writing tests with imported pytest.fixture methods, I get a few bogus errors. For context, I'm using Flask in Python. But, consider the following test.py example:

from common_stuff import app, client

def test_some_flask_think(client):
    # some test stuff

And in common_stuff.py:

@pytest.fixture
def client(app)
    return app.test_client()

If they're in the same file - no complains from Syntastic. However, in a separate file - no luck. An F811 error is listed in each instance.

Someone well likely has encountered the same thing before. Would greatly appreciate advice / pointers here.

Thanks!

BitPusher
  • 990
  • 1
  • 9
  • 20
  • Syntastic doesn't care about the contents of your files. Syntastic is just a shorthand for running linters: pep8, pyflakes, or whatever else you have configured. What linter complains about your code, and how do you configure it not to do that when you run it in a terminal? – lcd047 May 09 '18 at 03:20
  • If Syntastic were purely running a linter here (using `flake8`), then I'd expect to see the same error in that output. However, here that is not the case. Whats befuddling to me is the `import` clearly states the thing is being imported. But assumes it is inadequate to use as an argument to the fixture/test method. At least that's what I speculate may be happening. – BitPusher May 09 '18 at 14:38
  • You can save a lot of time if you redirect a tiny fraction of the energy you spend on speculations to reading the manual. Then you'll be able to tell exactly what syntastic runs, and you'll be able to change that to suit your needs. – lcd047 May 09 '18 at 15:02
  • Your assumption of how much time was spent speculating is incorrect. Maybe a few minutes at best. The point of asking here is if someone came across the precise same scenario, there may be a simple answer and that could educate others. Yes, there is value in RTFM. However, that's not really the point. That, if anything would be a last ditch effort. Last, but not least, a bit more politeness would go a long way. – BitPusher May 09 '18 at 19:34
  • Possible duplicate of [In py.test, what is the use of conftest.py files?](https://stackoverflow.com/questions/34466027/in-py-test-what-is-the-use-of-conftest-py-files) – BitPusher May 09 '18 at 20:13

1 Answers1

0

To answer my own question, and in hopes of kindly educating others who may run into the same issue...

Syntastic can use a variety of linters for Python. The default which was configured on my system happened to be flake8. I was able to determine this by running :SyntasticInfo while a Python buffer was active in Vim.

The error noted above, has a code of F811 which is also documented in the Flake 8 error code docs. After additional research, this may well be a bug in Flake8. However, there is a more idiomatic solution with pytest, noted in the following SO post. A concrete example of conftest.py can be found in this post. In a nutshell, common_stuff.py can be renamed to conftest.py, the import removed, and pytest will bootstrap the necessary test fixtures accordingly.

BitPusher
  • 990
  • 1
  • 9
  • 20