2

I am looking for a way to create temporary models to test a simple django app part of a larger django project.

If it was not of the models I need to test the app, I would just create a tests/ directory within that app, however it does not work since it requires the migrations.

I'd like to avoid to:

  • create a sibling test app with the tests in it
  • create another application in another repository and install through pip
  • pollute the database with the test models
  • create the tables manually using SQL

I use both sqlite3 and MySQL. Django 1.9.5

What I tried:

  1. Create tables manually
  2. Django Fake Models does not seem to work
John Moutafis
  • 22,254
  • 11
  • 68
  • 112
jrobichaud
  • 1,272
  • 1
  • 11
  • 23
  • I know you want to avoid creating a new sibling test app, but I don't think of any other way. In case someone's also looking for this, there's this similar _older question_: https://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for-testing The top voted solutions don't work anymore but these two answers should work in more recent django versions: https://stackoverflow.com/a/8719352/1092815 and https://stackoverflow.com/a/34900947/1092815 In other words I would load the sibling app only when testing (using environment variables or `if 'test' in sys.argv`). – GabLeRoux Jun 06 '17 at 13:18

0 Answers0