diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff5413ab..ddd59a2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: python-version: ${{ matrix.python-version }} - run: python -m pip install Django~="${{ matrix.django-version }}.0" - run: python -m pip install -e .[test] - - run: python -m pytest + - run: python -m pytest -m "not selenium" - uses: codecov/codecov-action@v3 Selenium: @@ -85,5 +85,5 @@ jobs: python-version: ${{ matrix.python-version }} - run: python -m pip install Django - run: python -m pip install -e .[test,selenium] - - run: python -m pytest + - run: python -m pytest -m selenium - uses: codecov/codecov-action@v3 diff --git a/tests/conftest.py b/tests/conftest.py index b5e37416..3ac31e51 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,11 @@ from selenium.common.exceptions import WebDriverException +def pytest_configure(config): + config.addinivalue_line( + "markers", "selenium: skip if selenium is not installed" + ) + def random_string(n): return "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(n) diff --git a/tests/test_forms.py b/tests/test_forms.py index 70a89d55..6e81f50b 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -82,12 +82,14 @@ def test_allow_clear(self, db): "primary_genre", None ) + @pytest.mark.selenium def test_no_js_error(self, db, live_server, driver): driver.get(live_server + self.url) with pytest.raises(NoSuchElementException): error = driver.find_element(By.XPATH, "//body[@JSError]") pytest.fail(error.get_attribute("JSError")) + @pytest.mark.selenium def test_selecting(self, db, live_server, driver): driver.get(live_server + self.url) with pytest.raises(NoSuchElementException): @@ -298,6 +300,7 @@ def test_many_selected_option(self, db, genres): ), widget_output assert selected_option2 in widget_output or selected_option2a in widget_output + @pytest.mark.selenium def test_multiple_widgets(self, db, live_server, driver): driver.get(live_server + self.url) with pytest.raises(NoSuchElementException): @@ -641,6 +644,7 @@ class TestHeavySelect2MultipleWidget: bool(os.environ.get("CI", False)), reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772", ) + @pytest.mark.selenium def test_widgets_selected_after_validation_error(self, db, live_server, driver): driver.get(live_server + self.url) WebDriverWait(driver, 3).until( @@ -678,6 +682,7 @@ class TestAddressChainedSelect2Widget: url = reverse("model_chained_select2_widget") form = forms.AddressChainedSelect2WidgetForm() + @pytest.mark.selenium def test_widgets_selected_after_validation_error( self, db, live_server, driver, countries, cities ): @@ -757,6 +762,7 @@ def test_widgets_selected_after_validation_error( assert len(country_names_from_browser) != Country.objects.count() assert country_names_from_browser == country_names_from_db + @pytest.mark.selenium def test_dependent_fields_clear_after_change_parent( self, db, live_server, driver, countries, cities ):