擅长:python、mysql、java
<p>是的。</p>
<p>我在Mac电脑上,使用的是PyCharm 4.5.1专业版。你的平台和版本可能有点不同,但是如果你确定你使用的是最新版本,它应该可以工作。</p>
<p><strong>编辑:</strong>我已更新此答案并上载了新的屏幕截图。</p>
<p>您需要设置工作目录<strong>和<code>PYTHONPATH</code>环境变量。</p>
<p>工作目录设置要由正在运行的任务使用的目录。并且<code>PYTHONPATH</code>环境变量将目录添加到<code>sys.path</code></p>
<p>转到<code>Run</code>->;<code>Edit Configurations</code></p>
<p>在弹出的对话框中,导航到<code>Defaults</code>->;<code>Python tests</code>->;<code>Unittests</code></p>
<p>设置工作目录和<code>PYTHONPATH</code>环境变量,就都设置好了。测试将从该工作目录自动运行,并具有所需的sys.path。如果用冒号分隔,则可以在<code>PYTHONPATH</code>环境变量中包含多个路径<code>:</code></p>
<p>例如:</p>
<pre><code>PYTHONPATH=/path/to/dir:/path/to/other/dir
</code></pre>
<p>如果您已经有一些现有的测试配置,您可能希望删除它们,以便在运行测试或设置工作目录时重新创建它们,并为每个配置<code>PYTHONPATH</code>。可以从同一对话框窗口中删除它们</p>
<p><code>Run</code>->;<code>Edit Configurations</code>然后展开<code>Python Tests</code>查看现有的测试配置</p>
<p>如果不想删除现有的测试配置,只需分别为每个现有的测试配置指定工作目录。</p>
<p><img src="https://i.stack.imgur.com/DTd9o.png" alt="enter image description here"/></p>