擅长:python、mysql、java
<p>作为jcoppens<a href="https://stackoverflow.com/a/28794244/54056">mentioned</a>,您需要修复导入。但是你的测试还有几个问题。你知道吗</p>
<p>你的测试应该是:</p>
<pre><code>def test_getSex():
assert len(person1.getSex()) == 1
</code></pre>
<p>注意<code>getSex()</code>-如果没有括号,则表示方法的长度,而不是返回的结果。你知道吗</p>
<p>作为一般提示,当您开始测试时,请使用print语句确保您正在测试您认为正在测试的内容。e、 g.打印出<code>person1</code>,将<code>person1.getSex()</code>赋给一个变量,并在断言它之前打印出来。你知道吗</p>
<p>而且在我看来,您的测试函数并不需要<code>@pytest.fixture</code>修饰符,因此可以删除它。你知道吗</p>