Opened 8 years ago

Closed 5 years ago

Last modified 4 years ago

#6298 closed (fixed)

Include sample settings file(s) to run django unit tests i.e. make running unit tests easier

Reported by: curtis@… Owned by: kmtracey
Component: Testing framework Version: master
Severity: Keywords:
Cc: tobias Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Currently, running unit tests require a little bit of setup that in many cases (the most common case?) isn't needed. If sqlite3 is installed and no settings file is defined, this patch sets up a fake settings module with which to run the tests. In addition, it tries to use the version of django associated (checked out) with the tests and displays the path of the version being used.

This patch would allow someone to quickly checkout and run the tests for e.g.:

svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
curtis$ python django-trunk/tests/runtests.py

Running tests against /Users/curtis/Projects/django-trunk/django
----------------------------------------------------------------------
Ran 226 tests in 68.040s

OK

Attachments (7)

runtests.patch (1.7 KB) - added by curtis@… 8 years ago.
runtests-2.patch (1.4 KB) - added by curtis@… 8 years ago.
updated to use settings.configure()
test_settings.diff (5.1 KB) - added by tobias 6 years ago.
just one example file, plus doc updates
6298.diff (1.9 KB) - added by robhudson 5 years ago.
Updated patch after multidb
django_6298.diff (2.0 KB) - added by ericholscher 5 years ago.
Added docs to the settings file. Wrap docs.
django_6298.2.diff (2.0 KB) - added by ericholscher 5 years ago.
Fix spacing in settings file.
django_6298.3.diff (2.0 KB) - added by ericholscher 5 years ago.
Fix spacing in settings file.

Download all attachments as: .zip

Change History (28)

Changed 8 years ago by curtis@…

comment:1 Changed 8 years ago by curtis@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Make running django unit tests easier to Don't require a settings file to run django unit tests i.e. make running unit tests easier

comment:2 Changed 8 years ago by Collin Grady <cgrady@…>

That seems like a poor way to do it - couldn't you use settings.configure() instead of making a fake module?

comment:3 Changed 8 years ago by curtis@…

Collin, thanks for the pointer. That's a much easier way to do it!

Changed 8 years ago by curtis@…

updated to use settings.configure()

comment:4 Changed 7 years ago by Simon Greenhill <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:5 Changed 7 years ago by russellm

  • Resolution set to wontfix
  • Status changed from new to closed

The implementation looks good, but I'm not convinced this is a good idea. Setting up a settings file isn't that difficult, and the documentation already describes the minimum requirements for a settings file.

Plus, as it stands, the requirement to provide a settings file to runtests.py serves as a mental reminder that you are only ever testing a single setup - other databases etc may yield different results. Giving runtests.py a 'default behaviour' suggests that there is a 'default configuration' which is all that needs to be tested. The runtests script is really for the benefit of developers, and it doesn't hurt to remind developers that anything they do for Django needs to be checked on multiple backends.

comment:6 Changed 6 years ago by ericholscher

  • milestone set to 1.2

I talked with Jacob about this at EuroDjangoCon, and I think it would be a good idea. It really does allow people to get started running the test suite, and during things like sprints and such, that is a decently large time sink. I have a simple patch that allows you to do this, but if Russ thinks it shouldn't be included in core, then perhaps documenting how to get the test suite up and running would be a good solution as well.

comment:7 Changed 6 years ago by russellm

The process of setting up to run the test suite is already documented. I'm sure we can improve the presentation, but all the necessary information is already there.

I don't buy the 'time sink' argument - the settings file for SQLite requires exactly 1 line:

DATABASE_BACKEND='sqlite3'

Configuring for PosgreSQL/MySQL requires only 3 more lines, plus the overhead of creating a database instance. I find it hard to believe that this is the impediment slowing progress at a sprint, even if there are a lot of first-time contributors.

That said, I'm not mortally opposed to this idea. If the community really wants this, I'm willing to hold my nose and ignore the smell - ultimately, it doesn't have any real impact on my daily operation, since I have my suite of settings files already configured.

comment:8 Changed 6 years ago by russellm

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Eric, Joseph and I have arrived at a compromise suggestion - checking in a test_sqlite.py settings file that is sufficient for testing sqlite, but still requires that you specify --settings=test_sqlite at the command line. Will commit soon.

comment:9 Changed 6 years ago by tobias

  • Summary changed from Don't require a settings file to run django unit tests i.e. make running unit tests easier to Include sample settings file(s) to run django unit tests i.e. make running unit tests easier
  • Triage Stage changed from Design decision needed to Accepted

marking as Accepted per Russell

What about including sample test settings files for other databases as well? When ident authentication is enabled, postgres only needs one additional setting (the db name). e.g.:

DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'django_unit_tests'

We could include the file without the DB name (and with the other empty settings) just to give people something to fill out, and emphasize the fact that it's good to run the tests with different DBs.

I tend to prefer 'test_sqlite.py.example' naming, which encourages folks to copy the file locally and modify it to fit their needs (without risking committing it back to SVN or including it in a patch by accident).

Thoughts?

comment:10 Changed 6 years ago by tobias

  • Has patch unset
  • Owner changed from nobody to tobias
  • Status changed from reopened to new

Oh, and the docs should probably updated as well. For lazy people (like myself) who only read the docs when they've tried it themselves first and then failed, it took awhile to figure out that you only need database settings in the settings file, not a full settings file. Given that the tests typically break if you do provide a full settings file, somehow making this more obvious might be a good thing.

I'll work on a patch hopefully later today

comment:11 Changed 6 years ago by tobias

  • Status changed from new to assigned

comment:12 Changed 6 years ago by tobias

<freakboy3742> tobias: Ok - the test_foo.py.example idea works for me.
<freakboy3742> As long as:
<freakboy3742> 1) It has a big set of instructions in the file "copy this, fill in these values, etc"
<freakboy3742> 2) Docs get updated (but keep the verbose versions)
<freakboy3742> (verbose instructions, that is)
<freakboy3742> 3) test_sqlite.py doesn't need to be an example - we can ship that one since it rely on passwords etc.

comment:13 Changed 6 years ago by tobias

  • Has patch set

comment:14 Changed 6 years ago by tobias

  • Owner changed from tobias to kmtracey
  • Status changed from assigned to new

assigning to kmtracey for review

comment:15 Changed 6 years ago by tobias

  • Cc tobias added

comment:16 Changed 6 years ago by kmtracey

  • Owner changed from kmtracey to tobias

Back to you for updates based on what all people were saying in IRC.

comment:17 Changed 6 years ago by tobias

  • Status changed from new to assigned

Changed 6 years ago by tobias

just one example file, plus doc updates

comment:18 Changed 6 years ago by tobias

  • Owner changed from tobias to kmtracey
  • Status changed from assigned to new

Here's a much smaller patch w/corresponding doc changes. Hopefully this is a good compromise b/t the original intent of this ticket (make it easier to test w/sqlite) and Jacob & Alex's wishes to do this entirely in documentation.

comment:19 Changed 6 years ago by kmtracey

  • Patch needs improvement set

The mutlidb commit added a requirement that multiple databases be defined in order for the full Django test suite to pass. See: http://docs.djangoproject.com/en/dev/internals/contributing/#running-the-unit-tests. We're going to need to update the patch for this to account for that (and I think that makes a sample file even more needed. Whipping up a test settings file is no longer trivial). I'll get to it eventually but if anyone interested has free time before me feel free to update the patch.

Changed 5 years ago by robhudson

Updated patch after multidb

Changed 5 years ago by ericholscher

Added docs to the settings file. Wrap docs.

Changed 5 years ago by ericholscher

Fix spacing in settings file.

Changed 5 years ago by ericholscher

Fix spacing in settings file.

comment:20 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(In [12547]) Fixed #6298 - Added sample settings file to run the Django test suite (SQLite). Thanks, Eric Holscher.

comment:21 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top