fedora-infra / fedora-messaging

A library for sending AMQP messages with JSON schema in Fedora infrastructure
GNU General Public License v2.0
53 stars 52 forks source link

Pytest does not work on Fedora 35 #256

Closed gridhead closed 2 years ago

gridhead commented 2 years ago

Context

I am working on https://github.com/fedora-infra/fedora-messaging/issues/253 and want the test to be automated too alongside the usual packaging tasks.

What did I do?

  1. Cloned the repo
  2. Created a virtual environment
  3. Activated the virtual environment
  4. Install the requirements
  5. Ran pytest
  6. Saw this.
    
    ============================================================================================================================ test session starts ============================================================================================================================
    platform linux -- Python 3.10.4, pytest-6.2.4, py-1.11.0, pluggy-0.13.1
    rootdir: /forks/fedora-messaging, configfile: tox.ini, testpaths: fedora_messaging/tests/unit/
    collected 141 items / 1 error / 3 skipped / 137 selected

================================================================================================================================== ERRORS =================================================================================================================================== _____ ERROR collecting fedora_messaging/tests/unit/test_api.py __ ImportError while importing test module '/forks/fedora-messaging/fedora_messaging/tests/unit/test_api.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib64/python3.10/importlib/init.py:126: in import_module return _bootstrap._gcd_import(name[level:], package, level) fedora_messaging/tests/unit/test_api.py:23: in import pytest_twisted E ModuleNotFoundError: No module named 'pytest_twisted' ============================================================================================================================= warnings summary ============================================================================================================================== ../../usr/lib/python3.10/site-packages/crochet/_eventloop.py:13 /usr/lib/python3.10/site-packages/crochet/_eventloop.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses import imp

-- Docs: https://docs.pytest.org/en/stable/warnings.html ========================================================================================================================== short test summary info ========================================================================================================================== ERROR fedora_messaging/tests/unit/test_api.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ================================================================================================================== 3 skipped, 1 warning, 1 error in 0.77s ===================================================================================================================


7. Confirmed that `pytest_twisted` is indeed installed.

Is the test broken or am I doing something wrong?
gridhead commented 2 years ago

Here's the log as I promised.

I install the dependencies from the requirements.txt and dev_requirements.txt into an activated virtual environment first and then, do a python3 setup.py install on it.

Then I run pytest to see this.

============================================================================================================================ test session starts ============================================================================================================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: /actual/fedora-messaging, configfile: tox.ini, testpaths: fedora_messaging/tests/unit/
plugins: twisted-1.13.4
collected 205 items

fedora_messaging/tests/unit/test_api.py ...................                                                                                                                                                                                                           [  9%]
fedora_messaging/tests/unit/test_cli.py ..............................F..........                                                                                                                                                                                     [ 29%]
fedora_messaging/tests/unit/test_config.py ........................                                                                                                                                                                                                   [ 40%]
fedora_messaging/tests/unit/test_example.py .                                                                                                                                                                                                                         [ 41%]
fedora_messaging/tests/unit/test_message.py ....................................................                                                                                                                                                                      [ 66%]
fedora_messaging/tests/unit/test_schema_utils.py ......                                                                                                                                                                                                               [ 69%]
fedora_messaging/tests/unit/test_testing.py .......                                                                                                                                                                                                                   [ 73%]
fedora_messaging/tests/unit/twisted/test_consumer.py ...................                                                                                                                                                                                              [ 82%]
fedora_messaging/tests/unit/twisted/test_factory.py ..........                                                                                                                                                                                                        [ 87%]
fedora_messaging/tests/unit/twisted/test_protocol.py ................                                                                                                                                                                                                 [ 95%]
fedora_messaging/tests/unit/twisted/test_service.py ..........                                                                                                                                                                                                        [100%]

================================================================================================================================= FAILURES ==================================================================================================================================
__________________________________________________________________________________________________________________ CallbackFromFilesytem.test_invalid_file __________________________________________________________________________________________________________________

self = <fedora_messaging.tests.unit.test_cli.CallbackFromFilesytem testMethod=test_invalid_file>

    def test_invalid_file(self):
        """Assert an exception is raised if the Python file can't be executed."""
        with self.assertRaises(click.ClickException) as cm:
            cli._callback_from_filesystem(
                os.path.join(FIXTURES_DIR, "bad_cb") + ":missing"
            )

        if sys.version_info >= (3, 10):
            exc_msg = "invalid syntax. Perhaps you forgot a comma?"
        else:
            exc_msg = "invalid syntax"
>       self.assertEqual(
            "The {} file raised the following exception during execution: "
            "{} (bad_cb, line 1)".format(
                os.path.join(FIXTURES_DIR, "bad_cb"),
                exc_msg,
            ),
            cm.exception.message,
        )
E       AssertionError: 'The [116 chars]: invalid syntax. Perhaps you forgot a comma? (bad_cb, line 1)' != 'The [116 chars]: invalid syntax (bad_cb, line 1)'
E       - The /actual/fedora-messaging/fedora_messaging/tests/fixtures/bad_cb file raised the following exception during execution: invalid syntax. Perhaps you forgot a comma? (bad_cb, line 1)
E       ?                                                                                                                                         -----------------------------
E       + The /actual/fedora-messaging/fedora_messaging/tests/fixtures/bad_cb file raised the following exception during execution: invalid syntax (bad_cb, line 1)

fedora_messaging/tests/unit/test_cli.py:493: AssertionError
============================================================================================================================= warnings summary ==============================================================================================================================
fedora_messaging/tests/unit/test_api.py::test_consume_unexpected_crash
fedora_messaging/tests/unit/test_api.py::test_consume_successful_halt
  /actual/fedora-messaging/venv/lib/python3.10/site-packages/crochet/_eventloop.py:135: DeprecationWarning: isSet() is deprecated, use is_set() instead
    if self._result_set.isSet():

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================================================== short test summary info ==========================================================================================================================
FAILED fedora_messaging/tests/unit/test_cli.py::CallbackFromFilesytem::test_invalid_file - AssertionError: 'The [116 chars]: invalid syntax. Perhaps you forgot a comma? (bad_cb, line 1)' != 'The [116 chars]: invalid syntax (bad_cb, line 1)'
================================================================================================================= 1 failed, 204 passed, 2 warnings in 2.33s =================================================================================================================

The branch on which I run the test on is packit which is derived from stable with no code changes.

@abompard, for your reference ;)

abompard commented 2 years ago

Fixed by 3515d60, thanks. It's only in the develop branch at the moment though.

gridhead commented 2 years ago

No issues. I will rebase packit branch atop the develop one for now. Though I wonder if the source would keep up.