From c712d11d25f9c7c572409fe39c79d4d78744a36e Mon Sep 17 00:00:00 2001 From: Daniel Harding Date: Sun, 17 Mar 2024 16:23:14 +0300 Subject: [PATCH] Allow more control over tox Selenium tests Instead of unconditionally enabling Selenium tests for the py311-dj42-postgresql tox environment, enable them by default for that environment but allow them to be disabled if the user's DJANGO_SELENIUM_TESTS environment variable is empty. This will allow the user to run DJANGO_SELENIUM_TESTS= tox to run the full tox test suite with Selenium tests disabled. --- docs/contributing.rst | 6 ++++++ tests/test_integration.py | 2 +- tox.ini | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index 55d9a5ca7..0021a88fa 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -85,6 +85,12 @@ or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable:: $ DJANGO_SELENIUM_TESTS=true make coverage $ DJANGO_SELENIUM_TESTS=true tox +Note that by default, ``tox`` enables the Selenium tests for a single test +environment. To run the entire ``tox`` test suite with all Selenium tests +disabled, run the following:: + + $ DJANGO_SELENIUM_TESTS= tox + To test via ``tox`` against other databases, you'll need to create the user, database and assign the proper permissions. For PostgreSQL in a ``psql`` shell (note this allows the debug_toolbar user the permission to create diff --git a/tests/test_integration.py b/tests/test_integration.py index fee67b7d1..127406df8 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -547,7 +547,7 @@ def test_auth_login_view_without_redirect(self): @unittest.skipIf(webdriver is None, "selenium isn't installed") @unittest.skipUnless( - "DJANGO_SELENIUM_TESTS" in os.environ, "selenium tests not requested" + os.environ.get("DJANGO_SELENIUM_TESTS"), "selenium tests not requested" ) @override_settings(DEBUG=True) class DebugToolbarLiveTestCase(StaticLiveServerTestCase): diff --git a/tox.ini b/tox.ini index 4910a9f6b..a0e72827a 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,7 @@ passenv= setenv = PYTHONPATH = {toxinidir} PYTHONWARNINGS = d - py311-dj42-postgresql: DJANGO_SELENIUM_TESTS = true + py311-dj42-postgresql: DJANGO_SELENIUM_TESTS = {env:DJANGO_SELENIUM_TESTS:true} DB_NAME = {env:DB_NAME:debug_toolbar} DB_USER = {env:DB_USER:debug_toolbar} DB_HOST = {env:DB_HOST:localhost}