python-gitlab / python-gitlab

A python wrapper for the GitLab API.
https://python-gitlab.readthedocs.io
GNU Lesser General Public License v3.0
2.24k stars 652 forks source link

Can't get pipelines test_report #1551

Closed davbr closed 3 years ago

davbr commented 3 years ago

Description of the problem, including code/CLI snippet

I'm trying to get a pipline's test report but i get the error seen below under Actual Behaviour.

Expected Behavior

test_report = pipeline.test_report.get()

where pipeline is of type gitlab.v4.objects.ProjectPipeline returns test report of pipeline

Actual Behavior

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dban/.local/lib/python3.8/site-packages/gitlab/base.py", line 62, in __getattr__
    value = self.__dict__["_attrs"][name]
KeyError: 'test_report'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dban/.local/lib/python3.8/site-packages/gitlab/base.py", line 82, in __getattr__
    return self.__dict__["_parent_attrs"][name]
KeyError: 'test_report'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dban/repos/api-gitlab/test.py", line 22, in <module>
    test_report = pipeline.test_report.get() # does not work
  File "/home/dban/.local/lib/python3.8/site-packages/gitlab/base.py", line 84, in __getattr__
    raise AttributeError(name)
AttributeError: test_report

Specifications

JohnVillalovos commented 3 years ago

Can you please provide a small snippet of code which demonstrates this issue?

davbr commented 3 years ago

sure :)

I have created this https://gitlab.com/davbr1/api_test_report which shows my issue.

just clone the repo, setup python and run the script

JohnVillalovos commented 3 years ago

Can you try using pipelines = project.pipelines.get() instead of list?

I believe in some cases the list doesn't give all the fields and need to use get. Not 100% sure on this.

davbr commented 3 years ago

i tied this:

pipeline = project.pipelines.get("339877782")
test_report = pipeline.test_report.get()

but unfortunately it gave the same error as before

JohnVillalovos commented 3 years ago

Okay. I just tested your code locally.

<class 'gitlab.v4.objects.pipelines.ProjectPipelineTestReport'> => {'total_time': 0.0, 'total_count': 2, 'success_count': 2, 'failed_count': 0, 'skipped_count': 0, 'error_count': 0, 'test_suites': [{'name': 'test', 'total_time': 0.0, 'total_count': 2, 'success_count': 2, 'failed_count': 0, 'skipped_count': 0, 'error_count': 0, 'suite_error': None, 'test_cases': [{'status': 'success', 'name': 'ASuccessfulTest', 'classname': 'foo1', 'file': None, 'execution_time': 0.0, 'system_output': None, 'stack_trace': None, 'recent_failures': None}, {'status': 'success', 'name': 'AnotherSuccessfulTest', 'classname': 'foo2', 'file': None, 'execution_time': 0.0, 'system_output': None, 'stack_trace': None, 'recent_failures': None}]}]}
    gl = gitlab.Gitlab("http://gitlab.com")
    project = gl.projects.get("28262778")

    pipelines = project.pipelines.list()
    pipeline = pipelines[0]
    # https://python-gitlab.readthedocs.io/en/stable/gl_objects/pipelines_and_jobs.html#id10
    test_report = pipeline.test_report.get()
    print(test_report)
JohnVillalovos commented 3 years ago

As a note, strange errors can occur when using 'http' instead of 'https' for specifying the Gitlab server. Shouldn't affect this case, but anything that causes a PUT or POST action will have errors.

davbr commented 3 years ago

weird! Are you using 2.9.0 from pypi and which python version. I have tried with 3.8 and 3.9

JohnVillalovos commented 3 years ago
$ pip freeze | grep python-gitlab
python-gitlab==2.9.0
$ python
Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gitlab
>>> print(gitlab.__version__)
2.9.0
davbr commented 3 years ago

this is a bit embarrassing then...but I found the issue.

Even though I where in my .venv vscode was still using an old version of the python-gitlab package (2.6.0).

Thank you for helping be out @JohnVillalovos and sorry for the noise.

JohnVillalovos commented 3 years ago

Oh. Glad you figured it out! 😊