用于envjasmine的python包装器
pyenvjasmine的Python项目详细描述
这是一个围绕envjasminejavascript的瘦python包装器 测试框架。
Installation
您可以使用pip:
pip install pyenvjasmine
或者您可以获取最新的源并从那里安装:
python setup.py install
另外,您可以直接从sources目录中使用它,在development mode (如果您想为项目做出贡献,这一点很有用):
pip install -e .
注意
有关开发模式的更多信息,请点击此处:
https://packaging.python.org/en/latest/distributing.html#working-in-development-mode
警告
从版本0.3.0开始,pyenvjasmine支持使用 不同的浏览器/引擎。无头浏览器rhino包含在 pyenvjasmine,但是为了使用其他引擎,必须安装 需要的浏览器。
现在,只支持phantomjs,因此请确保在 您想使用浏览器/引擎运行测试。如果需要 在jasmine 3.x上运行测试(也需要运行pyenvjasmine自己的 测试)。
Running pyenvjasmine tests
要在此代码上运行测试(与yourjavascript代码相反 要测试),请安装pyenvjasmine(和phantomjs),然后运行:
py.test
Run your own tests
最简单的方法是将“specs”(javascript测试)放到某个目录中 在代码中,然后在python测试中,只添加一个测试的新测试用例 运行所有javascript测试。
最简单的解决方案是将capture_output设置为false,这样就可以看到输出 从控制台上的js测试。像这样:
import pytest from pyenvjasmine.runner import Runner class TestJavaScript(object): def test_my_javascript(self): runner = Runner( testdir='/path/to/my/testdir', configfile='relative/path/to/configfile', testing_environment='phantomjs') success, stdout = runner.run() # assert on success, will be true if tests passed, False if any # test failed assert success, "One or more javascript tests have failed" # you can inspect stdout if you want to get more info, but it # will be printed to the console stdout anyway assert b'Total: 120' in stdout
在本例中,使用phantomjs浏览/引擎,将其替换为 rhino在rhino+jasmine 1.x上运行测试。
注意
phantomjs是首选的浏览器/引擎,所以这就是pyenvjasmine 如果在创建 一个新的runner实例。