Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect test imports #217

Merged
merged 5 commits into from
Aug 19, 2021
Merged

Protect test imports #217

merged 5 commits into from
Aug 19, 2021

Conversation

BrianJKoopman
Copy link
Member

Description

The HK Aggregator depends on spt3g/so3g, as a result the tests related to the aggregator fail during test collection if spt3g and so3g are not installed. This PR protects the relevant imports and runs a test for those imports. If the import test fails it uses the pytest-dependency plugin to skip the so3g/spt3g dependent tests.

This allows other tests to run, while reporting failed tests when an import test is run. For example, on a fresh system with just ocs and the requirements listed in requirements.txt installed testing yields:

===================================================================== test session starts =====================================================================
platform linux -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /vagrant/ocs, configfile: pytest.ini
plugins: docker-compose-3.2.1, cov-2.12.1, dependency-0.5.1
collected 53 items / 5 deselected / 48 selected

tests/test_aggregator.py Fsssssssssssssssss                                                                                                             [ 37%]
tests/test_crossbar_integration.py F                                                                                                                    [ 39%]
tests/test_influxdb_publisher.py ...                                                                                                                    [ 45%]
tests/test_matched_client.py .                                                                                                                          [ 47%]
tests/test_ocs_feed.py ..............                                                                                                                   [ 77%]
tests/test_pacemaker.py ...                                                                                                                             [ 83%]
tests/test_rename.py ....                                                                                                                               [ 91%]
tests/test_site_config.py ....                                                                                                                          [100%]

========================================================================== FAILURES ===========================================================================
___________________________________________________________________ test_so3g_spt3g_import ____________________________________________________________________

    @pytest.mark.dependency(name="so3g")
    def test_so3g_spt3g_import():
        """Test that we can import spt3g/so3g. Used to skip tests dependent on
        these imports.

        """
>       import so3g
E       ModuleNotFoundError: No module named 'so3g'

tests/test_aggregator.py:22: ModuleNotFoundError
___________________________________________________________________ test_so3g_spt3g_import ____________________________________________________________________

    @pytest.mark.dependency(name="so3g")
    def test_so3g_spt3g_import():
        """Test that we can import so3g. Used to skip tests dependent on
        this import.

        """
>       import so3g
E       ModuleNotFoundError: No module named 'so3g'

tests/test_crossbar_integration.py:29: ModuleNotFoundError
====================================================================== warnings summary =======================================================================
../../usr/lib/python3/dist-packages/twisted/internet/address.py:101
  /usr/lib/python3/dist-packages/twisted/internet/address.py:101: DeprecationWarning: The usage of `cmp` is deprecated and will be removed on or after 2021-06-01.  Please use `eq` and `order` instead.
    @attr.s(hash=False, repr=False, cmp=False)

tests/test_matched_client.py::test_extra_argv
  /vagrant/ocs/ocs/site_config.py:593: DeprecatedWarning: reparse_args is deprecated as of v0.6.0. Use site_config.parse_args instead
    ocs.site_config.reparse_args(args, '*control*')

-- Docs: https://docs.pytest.org/en/stable/warnings.html

---------- coverage: platform linux, python 3.8.10-final-0 -----------
Name                              Stmts   Miss  Cover
-----------------------------------------------------
ocs/__init__.py                       5      0   100%
ocs/agent/__init__.py                 0      0   100%
ocs/agent/aggregator.py             299    299     0%
ocs/agent/influxdb_publisher.py      95     44    54%
ocs/base.py                          14      0   100%
ocs/checkdata.py                    122    122     0%
ocs/client_http.py                   31     17    45%
ocs/client_t.py                      66     35    47%
ocs/matched_client.py                85     68    20%
ocs/ocs_agent.py                    400    329    18%
ocs/ocs_feed.py                     114     16    86%
ocs/ocs_twisted.py                   69     33    52%
ocs/ocsbow.py                       337    337     0%
ocs/rename.py                        49      0   100%
ocs/site_config.py                  268    140    48%
-----------------------------------------------------
TOTAL                              1954   1440    26%

=================================================================== short test summary info ===================================================================
FAILED tests/test_aggregator.py::test_so3g_spt3g_import - ModuleNotFoundError: No module named 'so3g'
FAILED tests/test_crossbar_integration.py::test_so3g_spt3g_import - ModuleNotFoundError: No module named 'so3g'
============================================= 2 failed, 29 passed, 17 skipped, 5 deselected, 2 warnings in 4.71s ==============================================

Motivation and Context

Fixes #209.

How Has This Been Tested?

This has been run on a fresh Ubuntu 20.04 system with just ocs and the modules listed in the requirements.txt file installed. Tests now complete, with failures where so3g imports are tested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Unless I am preparing a release, I have opened this PR onto the develop branch.

@BrianJKoopman BrianJKoopman merged commit bb4d9c1 into develop Aug 19, 2021
@BrianJKoopman BrianJKoopman deleted the protect-test-imports branch August 19, 2021 14:34
@BrianJKoopman BrianJKoopman mentioned this pull request Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests have undeclared dependencies
2 participants