Skip to main content
 首页 » 编程设计

python之如何在 Eclipse 中的 Django 项目中使用生菜

2024年10月25日25haluo1

我正在关注 Django Tutorial对于 Django v1.6,并使用 PyDev 在 eclipse 中运行它。我进入了有关测试的页面,我想我应该把它混在一起(阅读:先跑再走),然后再学习 Lettuce。

根据我在网上阅读的内容,默认情况下,生菜应该与 PyDev 捆绑在一起。这是有道理的,因为行 from lettuce import * 在我的 steps.py 中没有错误,但代码的其余部分确实如此:

from lettuce import * 
 
@step('Given my poll is (\d+) days in the future') 
def have_future_poll(step, number): 
    world.number = int(number) 

@step 的错误是:

Undefined variable: step step Found at: polls.tests.features.steps

step

对于世界来说是:

Undefined variable: world

所以我认为它导入不正确。

我应该如何在 eclipse 中使用 Lettuce?

请您参考如下方法:

要使用 lattuce.world,请尝试显式导入 world:from lattuce import world 应该可以工作 - 我在其他应用程序中遇到过这种现象也像 logicaldelete。但我不知道为什么它不像你那样工作......

要使用@step,您还应该导入该函数/文件/应用step(..):from polls.tests.features import steps。否则,在您的 .py 文件中没有定义名为 step(..) 的方法,并且 @step 成为不存在方法的装饰器。