传递 URL 以使用 nose testconfig 进行测试

passing a URL to test against with nose testconfig

有没有办法配置测试配置,以便我可以在命令行中传递 URL,即 'nosetests --tc=systest_url test_suit.py'

在 teamcity 上执行构建时,我需要 运行 针对开发和系统测试环境进行我的 selenium 测试。我们的团队决定使用 python 进行 UI 测试,我更像是一个 Java 的人,我想弄清楚插件是如何工作的,看起来我可以存储 url 在 yaml 中并将文件传递给 --tc 命令但似乎不起作用

我继承的代码如下所示:

URL = config['test' : 'https://www.google.com', ]


class BaseTestCase(unittest.TestCase, Navigation):
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Firefox()
        cls.driver.implicitly_wait(5)
        cls.driver.maximize_window()

        cls.driver.get(URL)

这显然不起作用

nose 有一个插件,nosetest-config。您可以指定一些配置文件并将文件名从 nose 传递给 --tc-file arg。

config.ini

[myapp_servers]
main_server = 10.1.1.1
secondary_server = 10.1.1.2

在您的测试文件中,您可以加载配置。

test_app.py

from testconfig import config

def test_foo():
     main_server = config['myapp_servers']['main_server']

然后,用 args 调用 nose

nosetests -s --tc-file example_cfg.ini

如文档中所述,您可以使用其他配置文件类型,如 YAML、JSON 甚至 Python 模块。

使用 nose-testconfig --tc 选项您可以覆盖配置值。使用冒号将键与值分开。例如,

nosetests test.py --tc=url:dev.example.com

将使值在 config['url'] 中可用。

from testconfig import config

def test_url_is_dev():
    assert 'dev' in config['url']