我有一堆由test_xyz.py
中的类组织的测试用例我必须通过与远程服务器的连接来运行这些测试(每个测试用例都将在所述连接上进行交易)。
我必须多次重复相同的测试(每次使用不同的连接凭据)。目前,我每次都手动更改凭据并重新运行测试。
我可以将凭据存储在字典中。但是,如何自动化测试以反复运行迭代存储在字典中的凭据?
根据我的阅读,灯具可能会有所帮助?但我不确定。
任何建议表示赞赏。提前谢谢。
test_xyz.py示例
conn = remote_conn(uname, pwd)
class Test_123:
"""Test Class"""
@pytest.mark.parametrize(...)
def test_1(self):
assert conn.do_this()
@pytest.mark.parametrize(...)
def test_2(self):
assert conn.do_that()
答案 0 :(得分:0)
尝试参数化你的灯具。我建议为remote_connection创建fixture并将其传递给测试。在这里你可以做到这一点。
plugins: xdist-1.11, profiling-1.2.6, cov-1.6
collecting ... collected 12 items
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn0-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn0-2] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn0-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn0-2] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn1-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn1-2] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn1-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn1-2] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn2-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_1[conn2-2] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn2-1] PASSED
../../../../../../Library/Preferences/PyCharm2017.1/scratches/scratch_8.py::Test_123::test_2[conn2-2] PASSED
================= 12 passed, 2 pytest-warnings in 0.08 seconds =================
Process finished with exit code 0
来自
的样本输出<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-html-shader@0.2.0/dist/aframe-html-shader.min.js"></script>
<body>
<a-scene>
<a-plane material="shader: html; target: #planeHTML" position="0 2 -6"></a-plane>
</a-scene>
<!-- HTML to render as a material. -->
<div style="width: 100%; height: 100%; position: fixed; left: 0; top: 0; z-index: -1; overflow: hidden">
<div id="boxHTML" style="background-image: url(cheesecake.png); color: white; width: 500px; height: 500px; font-size: 64px; font-family: monospace; text-align: center">
<p style="background: rgb(30, 30, 30); position: absolute; top: 25px; width: 500px">CHEESECAKE FOR YOU</p>
</div>
</div>
<div style="width: 100%; height: 100%; position: fixed; left: 0; top: 0; z-index: -1; overflow: hidden">
<div id="planeHTML">
<p style="text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;">Lorem ipsum</p>
</div>
</div>