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

Python 3.11: test_report_gives_package_version fails #94

Closed
musicinmybrain opened this issue Jun 20, 2022 · 3 comments · Fixed by #104
Closed

Python 3.11: test_report_gives_package_version fails #94

musicinmybrain opened this issue Jun 20, 2022 · 3 comments · Fixed by #104
Labels
Milestone

Comments

@musicinmybrain
Copy link
Contributor

On Python 3.11b3 (pre-release), test_report_gives_package_version fails. In a quick investigation, it wasn’t obvious to me what to do about it.

====================================================== FAILURES ======================================================
_________________________________________ test_report_gives_package_version __________________________________________

mock_import_module = <MagicMock name='import_module' id='140408684521360'>
mock_print = <MagicMock name='print' id='140408698005264'>

    @patch("builtins.print")
    @patch("importlib.import_module")
    def test_report_gives_package_version(mock_import_module, mock_print):
        module = TestModule()
        mock_import_module.return_value = module
    
        report("param")
    
>       mock_print.assert_called_with('param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param')

pyct/tests/test_report.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='print' id='140408698005264'>
args = ('param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param',)
kwargs = {}
expected = "print('param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param')"
actual = 'not called.'
error_message = "expected call not found.\nExpected: print('param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param')\nActual: not called."

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.
    
        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
>           raise AssertionError(error_message)
E           AssertionError: expected call not found.
E           Expected: print('param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param')
E           Actual: not called.

/usr/lib64/python3.11/unittest/mock.py:914: AssertionError
------------------------------------------------ Captured stdout call ------------------------------------------------
param=1.9.3                    # /mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param

It seems like the actual library is working as expected, and this is a test/mocking issue:

$ python3 -c 'from pyct import report; report("param")'
param=1.12.1                   # /home/ben/src/forks/pyct/_e/lib64/python3.11/site-packages/param
@maximlt
Copy link
Contributor

maximlt commented Jul 24, 2022

Thanks @musicinmybrain for opening this issue! pyct doesn't currently have any CI so I guess we have missed quite a number of warnings. I'll work on adding GH actions workflow, no ETA though 🙃

@maximlt maximlt added the task label Jul 24, 2022
@maximlt maximlt added this to the 0.4.9 milestone Jul 24, 2022
@s3v-
Copy link

s3v- commented Jan 28, 2023

Please see: python/cpython#98771

Just modifying the patching order solves the problem:

-@patch("builtins.print")
 @patch("importlib.import_module")
-def test_report_gives_package_version(mock_import_module, mock_print):
+@patch("builtins.print")
+def test_report_gives_package_version(mock_print, mock_import_module):
     module = TestModule()
     mock_import_module.return_value = module

Kind Regards

@musicinmybrain
Copy link
Contributor Author

Thanks for tying these two issues together. I’ll open a PR.

maximlt pushed a commit that referenced this issue Jan 30, 2023
* Ensure tox envs that run tests depend on cmd extra

* Fix test_report_gives_package_version on Python 3.11+

Fixes #94. See python/cpython#98771 and
#94 (comment).

* Add missing newline at end of pyct/tests/test_report.py

* Test Python 3.11 and add it to the trove classifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants