Repository: holoviz-dev/pyct (language: python)

Issue:
Python 3.11: test_report_gives_package_version fails
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
```


Discussion / hints:
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 🙃 
Please see: https://github.com/python/cpython/issues/98771

Just modifying the patching order solves the problem:
```diff
-@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
Thanks for tying these two issues together. I’ll open a PR.

Fix patch:
diff --git a/setup.py b/setup.py
index 43aaa9a..aaf7077 100755
--- a/setup.py
+++ b/setup.py
@@ -47,6 +47,7 @@ def get_setup_version(root, reponame):
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: 3.10',
+        'Programming Language :: Python :: 3.11',
         'Development Status :: 4 - Beta'
     ],
     author='HoloViz',
diff --git a/tox.ini b/tox.ini
index 212a6a4..a0a57b8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = {py36,py37,py38,py39,py310}-{flakes,unit,cmd_examples,build_examples,all}-{default}-{dev,pkg}
+envlist = {py36,py37,py38,py39,py310,py311}-{flakes,unit,cmd_examples,build_examples,all}-{default}-{dev,pkg}
 build = wheel
 
 [_flakes]
@@ -21,11 +21,11 @@ commands = {[_flakes]commands}
            {[_unit]commands}
            {[_cmd_examples]commands}
            {[_build_examples]commands}
-deps = .[examples, tests]
+deps = .[examples,tests,cmd]
 
 [_unit]
 description = Run unit tests
-deps = .[tests]
+deps = .[tests,cmd]
 commands = pytest pyct
            pyct --help
            pyct --version


Test patch:
diff --git a/pyct/tests/test_report.py b/pyct/tests/test_report.py
index 9f66ed5..5d27113 100644
--- a/pyct/tests/test_report.py
+++ b/pyct/tests/test_report.py
@@ -5,9 +5,9 @@ class TestModule:
     __version__ = "1.9.3"
     __file__ = "/mock/opt/anaconda3/envs/pyct/lib/python3.7/site-packages/param/__init__.py"
 
-@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
     
@@ -47,4 +47,4 @@ def test_report_gives_system_version(mock_platform, mock_print):
 def test_unknown_package_output(mock_print):
     report("fake_package")
     
-    mock_print.assert_called_with("fake_package=unknown           # not installed in this environment")
\ No newline at end of file
+    mock_print.assert_called_with("fake_package=unknown           # not installed in this environment")