Registry / testing / pytest-remotedata

pytest-remotedata

JSON →
library0.4.1pypypiunverified

Pytest-remotedata is a pytest plugin that provides control over unit tests requiring access to remote data from the internet. It allows developers to mark tests that either need remote data or should only run when internet access is disabled, helping to manage test suite runtime and dependencies. Originally part of the Astropy core package, it is currently at version 0.4.1 and sees active development with a consistent release cadence.

pip install pytest-remotedata
INSTALL
IMPORT
SIG · PYTEST-REMOTEDATA
P
pytest-remotedata
testingpythonv0.4.1
Install
2.7s avg
Import
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

remote_data
@pytest.mark.remote_data
Used to mark test functions, methods, or classes that require remote data access. The decorator is available via `pytest.mark` once the plugin is installed.
internet_off
@pytest.mark.internet_off
Used to mark test functions, methods, or classes that should run only when internet access is disabled. The decorator is available via `pytest.mark` once the plugin is installed.

To use `pytest-remotedata`, you mark your test functions with `@pytest.mark.remote_data` for tests requiring internet access or `@pytest.mark.internet_off` for tests that expect no internet. When `pytest` is run, tests marked with `remote_data` are skipped by default. They will only execute if the `--remote-data` command-line option (or `--remote-data=any`) is provided to `pytest`. Conversely, tests marked with `internet_off` will run when `--remote-data` is not provided (or `--remote-data=none`), and be skipped if `--remote-data` is active.

import pytest from urllib.request import urlopen import os @pytest.mark.remote_data def test_access_remote_data(): # This test will only run if pytest is invoked with --remote-data try: response = urlopen('https://httpbin.org/get', timeout=5) assert response.status == 200 print("Successfully accessed remote data.") except Exception as e: pytest.fail(f"Failed to access remote data: {e}") @pytest.mark.internet_off def test_no_internet_access(): # This test will run if pytest is invoked without --remote-data or with --remote-data=none # and should ideally not attempt network access. # For demonstration, we simulate no internet by trying to connect to a non-existent local address. import socket with pytest.raises(socket.error): # Expect a connection error if truly offline socket.create_connection(('localhost', 65535), timeout=0.1) print("Test passed when internet access is (simulated) off.") # To run the remote data test: # pytest --remote-data your_test_file.py # # To run the internet_off test (and skip remote_data tests): # pytest your_test_file.py (or pytest --remote-data=none your_test_file.py)
pytest --version
Debug
Known issues
breakingThe `-R` command-line option, introduced in `v0.4.0` for marking remote-data tests, was removed in `v0.4.1` as a workaround. Users upgrading from `v0.4.0` to `v0.4.1` should be aware that this option is no longer available.
fix
Do not use the `-R` option. Instead, rely on the standard `pytest --remote-data` for enabling remote data tests.
affects: 0.4.0 -> 0.4.1
gotchaBy default, tests marked with `@pytest.mark.remote_data` are skipped unless `pytest` is explicitly invoked with `--remote-data` or `--remote-data=any`. Users might mistakenly assume these tests will run when an internet connection is available without providing the flag.
fix
Always run `pytest` with `pytest --remote-data` to execute tests marked with `@pytest.mark.remote_data`. Use `pytest --remote-data=none` or simply `pytest` (without `--remote-data`) to skip them and run `internet_off` tests.
affects: All versions
gotchaEnabling strict remote data access by setting `remote_data_strict = true` in your `setup.cfg` will cause any test that attempts network access (e.g., via `urlopen`) to fail if it is *not* marked with `@pytest.mark.remote_data`. This is a powerful feature for catching unintended network calls but can lead to unexpected test failures if not understood.
fix
Ensure all tests that perform network requests are explicitly marked with `@pytest.mark.remote_data` when `remote_data_strict = true` is enabled. Review your `setup.cfg` for this setting.
affects: All versions
Upgrade
Version history
0.4.1latest on PyPI · released Sep 26, 2023
Audit
Dependencies
pytestrequiredThis is a pytest plugin and requires pytest to function. Compatible with pytest >= 4.6.
Agent activity
13 hits · last 30 days
node
12
Bingbot
1
Resources
pytest-remotedata — pip install pytest-remotedata · libregistry