How to run Scrapy unit tests in Pycharm
<p>I am working with Pycharm, trying to run scrapy unit tests - and it fails to run.
The errors are for missing imports, seems like all imports are failing.
e.g.</p>

<pre><code> Import error... "no module named mock"
</code></pre>

<p>what I did:</p>

<ol>
<li><p>Get scrapy from github</p></li>
<li><p>Run pip to install all dependencies from requirements.txt</p></li>
<li><p>Installed TOX , made sure I can run the tests using TOX.</p></li>
<li><p>Configured Pycharm to run tests using py.test</p></li>
</ol>

<p>I'm working on Ubuntu 14.04, Python 2.7 .</p>

<p>You need to additionally pip install the <a href="https://github.com/scrapy/scrapy/blob/master/tests/requirements.txt" rel="nofollow">tests requirements</a>:</p>

<pre><code>pip install -r tests/requirements.txt  # Python 2
pip install -r tests/requirements-py3.txt  # Python 3
</code></pre>

<p>That would install the <code>mock</code> package and solve the <code>no module named mock</code> on Python 2 (assuming you are installing into the same environment, you are running tests from).</p>

<hr>

<p>Note that to run the tests, you should use <code>tox</code> (which would also install the missing dependencies from <code>requirements.txt</code> during a test run setup phase):</p>

<pre><code>tox -- tests/test_loader.py
</code></pre>

<p>(just done all of that and the tests are running and passing for me).</p>

<p>FYI, here is my PyCharm configuration for the tox runner:</p>

<p><a href="http://i.stack.imgur.com/xPgw3.png" rel="nofollow"><img src="http://i.stack.imgur.com/xPgw3.png" alt="enter image description here"></a></p>

python python-2.7 scrapy pycharm