Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[-] Be able to run tox locally #243

Merged
merged 3 commits into from Oct 29, 2021
Merged

[-] Be able to run tox locally #243

merged 3 commits into from Oct 29, 2021

Conversation

timjklein36
Copy link
Collaborator

What

This PR makes it possible to run the full tox suite on a developer's local machine.

Why

This is really useful for making sure that developing changes do not break tests when run against older versions of Django or Python. This is also a good sanity check before submitting PRs, since it is exactly the same suite of tests that will run via CI.

How

To facilitate running tox locally, the only needed change was to add PGUSER=postgres to the setenv section of the tox.ini. This was defaulting to the developer's username so the tests could not connect to the DB that was running (since postgres is the usual default for DB user name).

Along with this, a new script was added (./postgres-docker) that makes it easy for a developer to spin up a PostgreSQL instance with all the proper extensions installed in order to run the full postgis test suite that some of the tox environment targets use.

Therefore, running tox locally can look something like this:

$ ./postgres-docker

Checking dependencies [docker]...
Starting 'model-bakery-postgres'...
4d2aa3b2c1d26cc5fbbf093c7548e804f4229c1a4955a118f64616ff4cd37e76
Waiting for DB container...
CREATE EXTENSION
CREATE EXTENSION
CREATE EXTENSION

$ tox

GLOB sdist-make: /home/tim/projects/model_bakery/setup.py
py36-django22-postgresql inst-nodeps: /home/tim/projects/model_bakery/.tox/.tmp/package/1/model_bakery-1.3.2.zip
py36-django22-postgresql installed: attrs==21.2.0,Django==2.2,importlib-metadata==4.8.1,iniconfig==1.1.1,model-bakery==1.3.2,packaging==21.0,Pillow==8.3.2,pluggy==1.0.0,psycopg2-binary==2.9.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.5,pytest-django==4.4.0,pytz==2021.3,sqlparse==0.4.2,toml==0.10.2,typing-extensions==3.10.0.2,zipp==3.6.0
py36-django22-postgresql run-test-pre: PYTHONHASHSEED='4241793774'
py36-django22-postgresql run-test: commands[0] | pytest
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.6.9, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
cachedir: .tox/py36-django22-postgresql/.pytest_cache
rootdir: /home/tim/projects/model_bakery, configfile: setup.cfg
plugins: django-4.4.0

... (REST OF OUTPUT TRUNCATED)

Note: there already existed a postgis-tests.sh script which was refactored a bit to utilize the new postgres-docker script for the same purpose that it was handling itself before.

@timjklein36 timjklein36 added the enhancement New feature or request label Oct 8, 2021
@github-actions
Copy link

github-actions bot commented Oct 8, 2021

@timjklein36 your pull request is missing a changelog!

@timjklein36
Copy link
Collaborator Author

@berinhard I don't think this PR needs a CHANGELOG update, since it is just devops stuff.

@berinhard berinhard merged commit 841f148 into main Oct 29, 2021
@berinhard berinhard deleted the tk/local-tox branch October 29, 2021 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants