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

Allow per-DB port specification for tox #1753

Closed
wants to merge 1 commit into from

Conversation

living180
Copy link
Contributor

As currently written, tox.ini allows specifying the DB port to use to connect to the test DB using a DB_PORT environment variable. However, it uses the same variable for the mysql, postgresql, and postgis environments. Thus if specifying a custom DB_PORT environment variable when running the full combination of tox environments, the mysql, postgresql, and postgis environments will all attempt to use the same DB port, which is unlikely to result in happiness.

Fix by checking for three new environment variables, POSTGRESQL_DB_PORT, POSTGIS_DB_PORT, and MYSQL_DB_PORT in the respective environments, falling back to DB_PORT (and then the hard-coded default) for backwards compatibility.

The motivation for this change is that I wanted to run postgresql within a container listening on a non-standard port for testing, but didn't have a way to run all tox over all the environments while setting the port for postgresql/postgis without also affecting the port for mysql.

  • I have added an item to the Pending section of docs/changes.rst.

As currently written, tox.ini allows specifying the DB port to use to
connect to the test DB using a DB_PORT environment variable.  However,
it uses the same variable for the mysql, postgresql, and postgis
environments.  Thus if specifying a custom DB_PORT environment variable
when running the full combination of tox environments, the mysql,
postgresql, and postgis environments will all attempt to use the same DB
port, which is unlikely to result in happiness.

Fix by checking for three new environment variables, POSTGRESQL_DB_PORT,
POSTGIS_DB_PORT, and MYSQL_DB_PORT in the respective environments,
falling back to DB_PORT (and then the hard-coded default) for backwards
compatibility.
@living180 living180 marked this pull request as draft April 2, 2023 13:35
Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the tox documentation fully but maybe factors or something could help with this; if a database environment is a factor (is it?) couldn't you run tox once per DB environment without having to list all individual combinations explicitly?

@matthiask
Copy link
Member

The following commands seem to produce the correct list of environments for the given databases:

tox -f postgresql -f postgis -l
tox -f mysql -l

@living180
Copy link
Contributor Author

Thanks for those commands. Unfortunately they only work with tox 4.x, and I have to stay with tox 3.x for the moment due to some other projects. I'd still like to be able to just run the full test suite with just a single tox invocation, although using the TOX_SKIP_ENV environment variable I might be able to select the appropriate environments similar to using factors as you suggested. I still need to see why my changes fail on tox 4.x, as they were based on tox 4.x documentation and work fine for tox 3.x.

@living180
Copy link
Contributor Author

So my changes in this PR didn't work with tox 4.x due to tox-dev/tox#2972. Closing.

@living180 living180 closed this Apr 4, 2023
@living180 living180 deleted the tox_db_port branch April 4, 2023 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants