这是一个经常以不同形式提出的问题,并经常得到"大声笑你没有做好"的回答.很确定这是因为人们(包括我)有一个常识场景试图用作实现,解决方案并不明显(如果你之前没有这样做过).
会接受一个"让飞出瓶子"的答案.
特定
project/
__init__.py
/code
__init__.py
sut.py
/tests
__init__.py
test_sut.py
Run Code Online (Sandbox Code Playgroud)
tests_sut.py开始的位置:
import code.sut
Run Code Online (Sandbox Code Playgroud)
在根目录中运行nosetests会导致:
ImportError: No module named code.sut
Run Code Online (Sandbox Code Playgroud)
旅行途径:
a)做亲戚使用
from ..code import sut
Run Code Online (Sandbox Code Playgroud)
b)将项目的根添加到PYTHONPATH
c)使用
sys.path.append
Run Code Online (Sandbox Code Playgroud)
在每个测试模块的开头导入之前添加..路径.
d)只记得做一个
setup.py
Run Code Online (Sandbox Code Playgroud)
在项目上,在运行测试之前将模块安装到站点包中.
因此,要求是在测试包根目录下面有可以访问项目的测试.上面的每一个对我来说都不觉得"自然",已经证明有问题或者看起来太辛苦了!
在java中这是有效的,但基本上是通过构建工具/ IDE将所有类放在类路径上.也许问题是我期待Python的"魔力"?在Flask webframework测试中已经注意到,选项d)似乎是首选.
在任何情况下,下面的陈述推荐一个首选的解决方案将消除我自己的"不自然"的感觉.
Rope是Python的重构库,RopeVim是一个调用Rope的Vim插件.
使用RopeVim的想法对我来说似乎很棒,有没有关于RopeVim"入门"的文档?
我遵循了以下文档:https://bitbucket.org/agr/ropevim/src/tip/README.txt
我想我正在寻找:
我们正在使用基于MongoDB用户的身份验证,我想快速运行一个命令来检查用户是否已在数据库中创建,以便puppet不会重复尝试创建用户.
以下是我们检查副本集是否已初始化的方法:
/usr/bin/mongo --host ${members[0]} --quiet --eval 'rs.status().ok' | grep -q 1
Run Code Online (Sandbox Code Playgroud)
验证可能有类似的技巧吗?我在这里检查了文档http://www.mongodb.org/display/DOCS/dbshell+%28mongo%29+Reference,我看不到这样做的方法吗?
我想使用SubSonic,因为它说它易于使用并节省时间.
尝试获取MySQL的连接字符串3小时后,我即将放弃它.
Building configuration from C:\Documents and Settings\user\My Documents\Visual Studio 2
008\Projects\ConfigurationItems\ConfigurationItemsMVC\Web.config
Adding connection to MySqlDataProvider
ERROR: Trying to execute generate
Error Message: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
Run Code Online (Sandbox Code Playgroud)
我无法转移它:错误消息:System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范.
我每次尝试运行subsonic.exe/generate都会得到它
这一切都很容易!
这是我的Web.Config
<!-- connectionString="Persist Security Info=False;database=config;server=localhost;user id=config;Password=config" -->
<connectionStrings>
<remove name="ConfigConnectString"/>
<add name="ConfigConnectString" connectionString="Persist Security Info=False;database=config;server=localhost;user id=userid;Password=password" providerName="MySql.Data.MySqlClient"
/>
</connectionStrings>
<SubSonicService defaultProvider="ConfigDatabase">
<providers>
<add type="SubSonic.MySqlDataProvider, SubSonic"
name="MySqlDataProvider"
generatedNamespace="Config"
connectionStringName="ConfigConnectString"
/>
</providers>
</SubSonicService>
Run Code Online (Sandbox Code Playgroud)
我尝试过几件事: