Django Testing in PyCharm Doesn't Load Fixtures

Hi there,

I wrote some tests for my Django models that depend on an initial dataset on the database. I'm used to have a initial_data.json fixture and optional fixtures that are loaded per test. These fixtures are loaded automatically during the manage.py test someapp command and all my tests pass. As I decided to do testing directly in PyCharm, I created a Django Test run configuration and set someapp as its target. I was surprised to discover that all tests failed.

The Traceback is normally something like:

Error

Traceback (most recent call last):

  File "/usr/lib/python2.7/unittest/case.py", line 318, in run

    self.setUp()

  File "/home/rafael/Repos/sales_fencing/sf/apps/sales_fencing/tests.py", line 29, in setUp

    user = User.objects.get(username='wilerson')

  File "/home/rafael/sf_env/local/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get

    return self.get_query_set().get(*args, **kwargs)

  File "/home/rafael/sf_env/local/lib/python2.7/site-packages/django/db/models/query.py", line 349, in get

    % self.model._meta.object_name)

DoesNotExist: User matching query does not exist.

Which indicates that the fixtures were not loaded by the Pycharm testing script. I confirmed this by observating the test_someapp database during the tests.

Is this a bug or should I configure Pycharm properly to load this fixtures during tests?

3 comments
Comment actions Permalink

Hi Rafael,

How are the optional fixtures loaded in your testing suit? Is it specified in your manage.py?

0
Comment actions Permalink

Hi Catherine,

I have an initial_data.json fixture and another two test-specific fixtures. They are all located in the project's root directory. Django's default behavior is to load the initial_data.json automatically and to load the tesf-specifc whenever if finds this file in the fixtures attribute of a test class.

0
Comment actions Permalink

Yes, it's PyCharm's bug. Please file an issue in our tracker -- http://youtrack.jetbrains.com/issues/PY

0

Please sign in to leave a comment.