我有一些固定装置在conftest.py实际测试功能中运行良好。但是,我想pytest_generate_tests()根据其中一些装置中的数据来参数化一些测试。
我想做的事情(简化):
-- conftest.py --
# my fixture returns a list of device names.
@pytest.fixture(scope="module")
def device_list(something):
return ['dev1', 'dev2', 'dev3', 'test']
-- test001.py --
# generate tests using the device_list fixture I defined above.
def pytest_generate_tests(metafunc):
metafunc.parametrize('devices', itertools.chain(device_list), ids=repr)
# A test that is parametrized by the above function.
def test_do_stuff(devices):
assert "dev" in devices
# Output should/would be:
dev1: pass
dev2: pass
dev3: pass
test: FAIL
Run Code Online (Sandbox Code Playgroud)
当然,我遇到的问题是在 pytest_generate_tests() 中,它抱怨 device_list 未定义。如果我尝试将其传入 pytest_generate_tests(metafunc, device_list),则会出现错误。
E …Run Code Online (Sandbox Code Playgroud) 我在 python 的 virtualenv 中运行一个项目。这是 virtualenv 的路径。
~/iss/issp/bin
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试使用以下命令运行激活脚本时:
source activate
Run Code Online (Sandbox Code Playgroud)
它引发以下错误。
:~/iss/issp/bin$ source activate
: command not found
bash: activate: line 4: syntax error near unexpected token `$'{\r''
'ash: activate: line 4: `deactivate () {
Run Code Online (Sandbox Code Playgroud)
这是脚本中的代码:
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
unset pydoc
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n …Run Code Online (Sandbox Code Playgroud) 为什么这个程序返回error: incompatible types: int cannot be converted to String?
public class StringConcatenation{
public static void main(String []args){
int[] testing = {0,1,3,4,5,6};
String mark = "";
for(int i=0;i<testing.length;i++)
{
// mark += testing[i]; But this line works fine
mark = testing[i]; /* This line doesn't work */
}
System.out.println(mark);
}
}
Run Code Online (Sandbox Code Playgroud)
StringConcatenation.java:8: 错误:类型不兼容:int 无法转换为字符串 mark = testing[i];
我知道如何清空python中的列表如何在Python中清空列表?
富兰的答案似乎与他的榜样有关.所以他的榜样是:
l1 = set([1, 2, 3])
l2 = l1
del l1[:]
TypeError: 'set' object does not support item deletion
Run Code Online (Sandbox Code Playgroud)
我只是l2通过写作制作成套装l2,并对其进行测试并且工作正常.
但是,当我用一组对象测试时,我收到了这个错误:
l1 = [1, 2, 3]
l2 = l1
Run Code Online (Sandbox Code Playgroud)
有没有其他方法来清空整个集合而不迭代它并使用l2?