无法在nosetests中使用nose-testconfig 0.6插件传递多个覆盖参数

1 投票
1 回答
1017 浏览
提问于 2025-04-15 23:00

我可以通过使用nose-testconfig 插件来覆盖多个配置参数,前提是我在命令行中传入这些参数,比如:

nosetests -c nose.cfg -s --tc=jack.env1:asl --tc=server2.env2:abc

但是当我在nose.cfg文件中定义相同的内容时,只有最后一个参数的值会被修改,比如:

tc = server2.env2:abc
tc = jack.env1:asl

我查看了这个插件的代码,感觉没有问题。这是插件代码的一部分:

    parser.add_option(

        "--tc", action="append", 
        dest="overrides",
        default = [],
        help="Option:Value specific overrides.")

配置:

    if options.overrides:
        self.overrides = []
        overrides = tolist(options.overrides)
        for override in overrides:
            keys, val = override.split(":")
            if options.exact:
                config[keys] = val
            else:                    
                ns = ''.join(['["%s"]' % i for i in keys.split(".") ])
                # BUG: Breaks if the config value you're overriding is not
                # defined in the configuration file already. TBD
                exec('config%s = "%s"' % (ns, val))

如果有人有任何线索,请告诉我。

1 个回答

0

请看我下面的 nose.cfg 文件:

[nosetests]
verbosity=2

tc-file = setup_config.py

tc-format = python

all-modules = True

tc = server2.env2:abc

tc = jack.env1:asl

我的配置文件是这样的:

[server2]

env2=server2

[jack]

env1=server1

在上面的例子中,只有 jack.env1:as1 的值是有效的(也就是说,最后一个值)。但是当我在命令行中指定相同的内容时,两个值都是有效的。

撰写回答