oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.29k stars 739 forks source link

Test Python Package fails #4517

Closed tarangchikhalia closed 5 months ago

tarangchikhalia commented 6 months ago

Describe the bug I pulled the latest changes from Github and trying to build the OpenGrok project in IntelliJ. While running the mvnw install, I am getting Error in the OpenGrok tools testing.

OpenGrok version 1.13.0 JDK 11 OS Ubuntu 22.04 Tomcat 10.1.x

To Reproduce Run the .mvnw install

Log

[INFO] --- exec:3.1.0:exec (Test python package) @ tools ---
.pkg: _optional_hooks target> python /home/tarang/Codespace/oss/opengrok-fork/tools/target/env/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_sdist target> python /home/tarang/Codespace/oss/opengrok-fork/tools/target/env/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_sdist target> python /home/tarang/Codespace/oss/opengrok-fork/tools/target/env/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py310: install_package target> python -I -m pip install --force-reinstall --no-deps /home/tarang/Codespace/oss/opengrok-fork/tools/.tox/.tmp/package/13/opengrok-tools-0.0.1.tar.gz
py310: commands[0] target> pytest -vv --color=yes src/test/python
py310: exit 2 (0.00 seconds) /home/tarang/Codespace/oss/opengrok-fork/tools> pytest -vv --color=yes src/test/python
py310: FAIL ✖ in 2.42 seconds
type: install_package target> python -I -m pip install --force-reinstall --no-deps /home/tarang/Codespace/oss/opengrok-fork/tools/.tox/.tmp/package/14/opengrok-tools-0.0.1.tar.gz
type: commands[0] target> pytest -vv --color=yes src/test/python
type: exit 2 (0.00 seconds) /home/tarang/Codespace/oss/opengrok-fork/tools> pytest -vv --color=yes src/test/python
.pkg: _exit target> python /home/tarang/Codespace/oss/opengrok-fork/tools/target/env/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  py310: FAIL code 2 (2.42=setup[2.42]+cmd[0.00] seconds)
  type: FAIL code 2 (2.25=setup[2.25]+cmd[0.00] seconds)
  evaluation failed :( (4.70 seconds)
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 255 (Exit value: 255)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
vladak commented 6 months ago

Cannot reproduce on Ubuntu 22.04.3 LTS with Python 3.10.12. In my case the output looks like this: pytest.txt

tarangchikhalia commented 6 months ago

Hmm.. Do you know what may have caused a problem like this?

vladak commented 6 months ago

Hmm.. Do you know what may have caused a problem like this?

No idea. You can try running the commands separately to see if it reproduces this outside of Maven.

tarangchikhalia commented 6 months ago

I cleaned the workspace and ran the maven build. I can see these errors:

    return when2(fn, Ellipsis).thenAnswer(replacement)
/home/tarang/Codespace/oss/opengrok-fork/tools/.tox/py310/lib/python3.10/site-packages/mockito/mockito.py:253: in when2
    obj, name = get_obj_attr_tuple(fn)
/home/tarang/Codespace/oss/opengrok-fork/tools/.tox/py310/lib/python3.10/site-packages/mockito/utils.py:158: in get_obj_attr_tuple
    return get_function_host(path)
/home/tarang/Codespace/oss/opengrok-fork/tools/.tox/py310/lib/python3.10/site-packages/mockito/utils.py:58: in get_function_host
    obj, name = find_invoking_frame_and_try_parse()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def find_invoking_frame_and_try_parse():
        # Actually we just want the first frame in user land; we're open for
        # refactorings here and don't yet decide on which frame exactly we hit
        # that user land.
        stack = inspect.stack(3)[2:10]
        for frame_info in stack:
            # Within `patch` and `spy2` we delegate to `when2` but that's not
            # user land code
            if frame_info[3] in ('patch', 'spy2'):
                continue

            source = ''.join(frame_info[4] or [])
            m = FIND_ID.match(source)
            if m:
                # id should be something like `os.path.exists` etc.
                id = m.group(1)
                parts = id.split('.')
                if len(parts) < 2:
                    raise TypeError("can't guess origin of '%s'" % id)

                frame = frame_info[0]
                vars = frame.f_globals.copy()
                vars.update(frame.f_locals)

                # Now that's a simple reduce; we get the initial value from the
                # locally available `vars`, and then reduce the middle parts via
                # `getattr`. The last path component gets not resolved, but is
                # returned as plain string value.
                obj = vars.get(parts[0])
                for part in parts[1:-1]:
                    obj = getattr(obj, part)
                return obj, parts[-1]

>       raise TypeError('could not destructure first argument')
E       TypeError: could not destructure first argument
vladak commented 6 months ago

What is the Python Mockito version used in your case ?

tarangchikhalia commented 6 months ago

Here is the Mockito details

Name: mockito
Version: 1.4.0
Summary: Spying framework
Home-page: https://github.com/kaste/mockito-python
Author: 
Author-email: 
License: MIT
Location: /home/tarang/.local/lib/python3.10/site-packages
Requires: 
Required-by: 
vladak commented 6 months ago

Here is the Mockito details


Name: mockito
Version: 1.4.0
Summary: Spying framework
Home-page: https://github.com/kaste/mockito-python

Here's quote from the latest Ubuntu test run (successful) via Github actions:

py310: OK ✔ in 26.94 seconds
type: install_deps target> python -I -m pip install GitPython mockito pytest pytest-mockito
type: install_package_deps target> python -I -m pip install filelock jsonschema==2.6.0 pyyaml 'requests>=2.20.0' resource
type: install_package target> python -I -m pip install --force-reinstall --no-deps /home/runner/work/opengrok/opengrok/tools/.tox/.tmp/package/2/opengrok-tools-0.0.1.tar.gz
type: freeze target> python -m pip freeze --all
type: certifi==2023.11.17,charset-normalizer==3.3.2,exceptiongroup==1.2.0,filelock==3.13.1,gitdb==4.0.11,GitPython==3.1.40,idna==3.6,iniconfig==2.0.0,JsonForm==0.0.2,jsonschema==2.6.0,JsonSir==0.0.2,mockito==1.4.0,opengrok-tools @ file:///home/runner/work/opengrok/opengrok/tools/.tox/.tmp/package/2/opengrok-tools-0.0.1.tar.gz#sha256=5cc5a86fa2547882a8a1d503b2f80da5794ff6c9f110c1c84f3d021432ddbd8b,packaging==23.2,pip==23.3.1,pluggy==1.3.0,pytest==7.4.4,pytest-mockito==0.0.4,Python-EasyConfig==0.1.7,PyYAML==6.0.1,requests==2.31.0,Resource==0.2.1,setuptools==69.0.2,six==1.16.0,smmap==5.0.1,tomli==2.0.1,urllib3==2.1.0,wheel==0.42.0

so the mockito version is the same.

tarangchikhalia commented 5 months ago

Not sure what the root cause of the problem was but it's working fine after I recloned the repository and rebuilt the app.