Development and Testing¶
How to work on and test Factory Djoy, across different versions of Django.
The test framework is already in place and
tox is configured to make use of
it. Therefore the quickest way to get going is to make use of it.
Clone the repository and drop in:
$ git clone email@example.com:jamescooke/factory_djoy.git $ cd factory_djoy
Create a virtual environment. This uses a bare call to
might prefer to use
$ make venv
Activate the virtual environment and install requirements:
$ . venv/bin/activate $ make install
Run all tests using
tox for all versions of Python and Django:
$ make test
Circle will also run linting before the main test run:
$ make lint
Testing with real Django projects¶
factory_djoy is asserted to work with different vanilla versions of Django.
For each version of Django tested, a default project and app exist in the
This structure has the following features:
test_frameworkcontains a folder for each version of Django. For example, the Django 1.11 project is in the
- Every project is created with the default
- In every project, a test settings file contains all the default settings as
installed by Django, but adds the
djoyappapp to the list of
models.pyand provides some models used for testing.
- Initial migrations for the models also exist, created using the matching
version of Django using the default
- Every project has a
testsfolder wired into the Django project root. This contains the tests that assert that
factory_djoybehaves as expected.
- Every project’s tests are executed through the default
toxis used to manage versions of Python and Django installed at test time.
The latest point release from each major Django version is used, excluding versions that are no longer supported.
The current version of Django in use at testing is compiled into each
To bump all package versions, the
bump_reqsrecipe can be used.
$ . venv/bin/activate $ make bump_reqs
Creating Django test projects for Django version¶
In order to add a version of Django to the test run:
Install the new version of Django into the current virtual environment:
$ pip install -U django
Ask the new version of Django to create projects and all
$ cd test_framework $ make build
Please note that creating a Django test project will fail if the target folder already exists. All
django*folders can be removed with
make clean- they can be rebuilt again identically with the
Add a requirements file for the new version of Django. For version
$ cd test_framework/requirements $ cat > django111.in Django>=1.11,<2^D $ make all
- Add the new Django version to
tox.ini. (There’s probably a better DRYer way to complete this.)
- Remember to add the new Django version to the README and do a release.
If there are multiple tests to run this can become inefficient with
Therefore, you can use the helper local environment configured inside
test_framework. This installs Python 3.5 and latest Django.
Create a new virtual environment in the
test_framework folder and install
$ cd test_framework $ make venv $ . venv/bin/activate $ make install
The test framework means that all the tests can be run on the test models and
factories using the standard
manage.py test command. So, if working with
Django 1.10, after calling
make build to create the app and folder
structure for that Django version, then all tests can be run with:
$ make test
Decide the new version number. Semantic versioning is used and it will look
In a Pull Request for the release:
- Update CHANGELOG with changes.
- Set version number in
- Ensure Pull Request is GREEN, then merge.
With the newly merged master:
Run tests locally:
$ make lint test
Clean out any old distributions and make new ones:
$ make clean dist
Test upload with Test PyPI and follow it with an install direct from Test PyPI (might need to create a
~/.pypircfile with settings for the test server:
$ make test-upload $ deactive $ virtualenv /tmp/tenv $ . /tmp/tenv/bin/activate $ make test-install
Tag release branch and push it:
$ git tag v1.2.3 $ git push origin --tags
Upload to PyPI:
$ make upload
- Ensure that link in CHANGELOG to the new diff works OK on GitHub.
- Check new docs are built on RTD.
Makefile has a couple of helper recipes (note this is different to
dist: Creates the distribution files.
upload: Push generated distribution to PyPI.
bump_reqs: Update all packages, commit updates to a new
auto/bump-requirementsbranch and push it to origin.
clean: Remove all compiled Python files, distributions, etc.