[Libosinfo] [PATCH osinfo-db 7/7] tests: Add custom pytest-3 --network-tests option

Fabiano Fidêncio fidencio at redhat.com
Thu Mar 21 12:23:02 UTC 2019


On Wed, 2019-03-20 at 17:53 -0400, Cole Robinson wrote:
> This wires up a --network-tests option to save us from needing the
> OSINFO_DB_NETWORK_TESTS environment variable, though that method
> still
> works. It works a bit differently in that unless specified it
> entirely
> takes the tests out of the pool and doesn't list any SKIP options.
> 
> IMO this is nicer because it makes the default test suite output less
> noisy. The network tests need to only be run periodically
> 
> Signed-off-by: Cole Robinson <crobinso at redhat.com>
> ---
>  tests/conftest.py  | 17 +++++++++++++++++
>  tests/test_urls.py |  9 ---------
>  2 files changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/tests/conftest.py b/tests/conftest.py
> index 8bd7236..5f9cd5b 100644
> --- a/tests/conftest.py
> +++ b/tests/conftest.py
> @@ -13,6 +13,23 @@ def _setup_env():
>  
>  _setup_env()
>  
> +
> +def pytest_addoption(parser):
> +    parser.addoption("--network-tests", action="store_true",
> default=False,
> +            help=("Run osinfo-db network tests. Same tests as
> triggered "
> +                  "by setting env variable
> OSINFO_DB_NETWORK_TESTS"))
> +
> +
> +def pytest_ignore_collect(path, config):
> +    """
> +    Entirely skip loading test_urls.py if the option wasn't
> specified
> +    """
> +    run_network = bool(config.getoption("--network-tests") or
> +            os.environ.get("OSINFO_DB_NETWORK_TESTS"))
> +    if os.path.basename(str(path)) == "test_urls.py" and not
> run_network:
> +        return True
> +
> +
>  # This will trigger some DATA_DIR validation
>  from . import util
>  dummy = util
> diff --git a/tests/test_urls.py b/tests/test_urls.py
> index 552e6eb..5900f3d 100644
> --- a/tests/test_urls.py
> +++ b/tests/test_urls.py
> @@ -1,15 +1,10 @@
>  # This work is licensed under the GNU GPLv2 or later.
>  # See the COPYING file in the top-level directory.
>  
> -import os
> -import pytest
> -
>  from . import util
>  
>  
>  @util.os_parametrize('_os', filter_images=True)
> - at pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is
> None,
> -                    reason='Network related tests are not enabled')
>  def test_images_url(_os):
>      broken = []
>      for image in _os.images:
> @@ -20,8 +15,6 @@ def test_images_url(_os):
>  
>  
>  @util.os_parametrize('_os', filter_trees=True)
> - at pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is
> None,
> -                    reason='Network related tests are not enabled')
>  def test_medias_url(_os):
>      broken = []
>      for media in _os.medias:
> @@ -32,8 +25,6 @@ def test_medias_url(_os):
>  
>  
>  @util.os_parametrize('_os', filter_media=True)
> - at pytest.mark.skipif(os.environ.get('OSINFO_DB_NETWORK_TESTS') is
> None,
> -                    reason='Network related tests are not enabled')
>  def test_trees_url(_os):
>      broken = []
>      for tree in _os.trees:

Cole,

This one didn't work for me at all. I've tried:
- `make check`
- `pytest3 tests/test_urls.py`

In both cases the URL tests were not skipped.

Is there some setup needed on my environment?

Best Regards,
-- 
Fabiano Fidêncio




More information about the Libosinfo mailing list