4

For a Django test I'd like to load a fixture, which is in a csv file. What is the best way to do that?

Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77

2 Answers2

7

Django's built-in fixtures functionality doesn't support CSV. You'd need to process the file automatically using the csv module, probably in the test's setUp method.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 1
    Obviously this is many years late, but for anyone still looking for something like this, the [django-excel-fixture](https://github.com/SKisContent/django-excel-fixture) may do the trick. You can use native xlsx files. – Sushil Jun 15 '18 at 10:50
1

For easier reuse I'd suggest my Django-PyFixture library. You'd then program your fixture in raw python, but it would semantically look like one more fixture.

Konstantine Rybnikov
  • 2,457
  • 1
  • 22
  • 29