擅长:python、mysql、java
<p>我只使用任何fixture来创建测试环境(比如数据库连接)或数据参数化。</p>
<p>如果您的数据相对简单,可以在测试用例中定义它:</p>
<pre><code>def test_action_without_fixtures():
sc = SuperCool()
sc.element = 'snow'
sc.melt()
assert sc.element == 'water'
</code></pre>
<p>参数化示例:</p>
<pre><code>@pytest.mark.parametrize("element, expected", [('snow', 'water'), ('tin', 'solder')])
def test_action_with_parametrization(element, expected):
sc = SuperCool()
sc.element = element
sc.melt()
assert sc.element == expected
</code></pre>