[英]Pytest Vim Syntastic - Avoid redefinition warning
I've set up Syntastic in Vim for Python development. 我已经在Vim中设置Syntastic进行Python开发。 Its been fantastic so far, but when writing tests with imported
pytest.fixture
methods, I get a few bogus errors. 到目前为止,它很棒,但是当使用导入的
pytest.fixture
方法编写测试时,出现了一些虚假错误。 For context, I'm using Flask in Python. 对于上下文,我在Python中使用Flask。 But, consider the following
test.py
example: 但是,请考虑以下
test.py
示例:
from common_stuff import app, client
def test_some_flask_think(client):
# some test stuff
And in common_stuff.py
: 并且在
common_stuff.py
:
@pytest.fixture
def client(app)
return app.test_client()
If they're in the same file - no complains from Syntastic. 如果它们位于同一文件中,则Syntastic不会抱怨。 However, in a separate file - no luck.
但是,在单独的文件中-没有运气。 An
F811
error is listed in each instance. 每个实例中都列出了
F811
错误。
Someone well likely has encountered the same thing before. 以前很可能有人遇到过同样的事情。 Would greatly appreciate advice / pointers here.
将不胜感激建议/指针在这里。
Thanks! 谢谢!
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. Syntastic可以为Python使用各种各样的短毛猫。 The default which was configured on my system happened to be
flake8
. 在我的系统上配置的默认值恰巧是
flake8
。 I was able to determine this by running :SyntasticInfo
while a Python buffer was active in Vim. 我可以通过在Vim中激活Python缓冲区时运行
:SyntasticInfo
来确定这一点。
The error noted above, has a code of F811
which is also documented in the Flake 8 error code docs . 上面提到的错误的代码为
F811
,在Flake 8错误代码docs中也有记录。 After additional research, this may well be a bug in Flake8 . 经过进一步研究,这很可能是Flake8中的错误 。 However, there is a more idiomatic solution with pytest, noted in the following SO post .
但是,在下面的SO post中指出了pytest的惯用解决方案。 A concrete example of
conftest.py
can be found in this post . conftest.py
的具体示例可以在这篇文章中找到。 In a nutshell, common_stuff.py
can be renamed to conftest.py
, the import removed, and pytest will bootstrap the necessary test fixtures accordingly. 简而言之,可以将
common_stuff.py
重命名为conftest.py
,删除导入,并且pytest将相应地引导必要的测试装置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.