Skip to content

Commit

Permalink
Add selenium test marker to stablize CI suite
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Nov 5, 2022
1 parent b568368 commit e62b8ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit e62b8ea

Please sign in to comment.