Skip to content

Commit

Permalink
Add offline testing to CI (#952)
Browse files Browse the repository at this point in the history
* Setup offline testing in CI

* Remove option

* Move network-accessing fixtures init into a pytest fixture

Move the OSHFixtures class into a pytest fixture to defer initializing
it (and therefore accessing the Internet) until the relevant test
functions are called.  This makes it possible for `pytest.mark.online`
to correctly skip them.  It also avoids initializing the fixtures class
multiple times -- now it should be initialized once per session.

While at it, move the global functions into the OSHFixtures class.  It
would need to access the class members anyway, and this seems cleaner
than passing its instance explicitly.

---------

Co-authored-by: Michał Górny <[email protected]>
  • Loading branch information
geographika and mgorny authored Nov 7, 2024
1 parent cdd92cd commit 40cfa45
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 262 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ jobs:
pip3 install -r docs/requirements.txt
- name: run tests ⚙️
run: python3 -m pytest
- name: run tests in offline mode
if: matrix.python-version == '3.10'
run: |
python3 -m pytest \
-m "not online" \
--disable-socket \
--deselect="tests/doctests/wcs_thredds.txt::wcs_thredds.txt" \
--deselect="tests/doctests/wfs_MapServerWFSCapabilities.txt::wfs_MapServerWFSCapabilities.txt" \
--deselect="tests/doctests/wms_geoserver_mass_gis.txt::wms_geoserver_mass_gis.txt"
- name: run coveralls ⚙️
run: coveralls
- name: build docs 🏗️
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
flake8
pytest
pytest-cov
pytest-socket
Pillow
tox
twine
Expand Down
1 change: 1 addition & 0 deletions tests/test_csw_geonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_csw_geonetwork():

SERVICE_URL3 = 'https://metawal.wallonie.be/geonetwork/srv/eng/csw'

@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL3),
reason='service is unreachable')
@pytest.mark.parametrize("esn_in", ['full', 'summary'])
Expand Down
Loading

0 comments on commit 40cfa45

Please sign in to comment.