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

"AttributeError: 'TestRailCase' object has no attribute 'result_fields'" even when not using the optional parameter #124

Closed
EOssesFrazoni opened this issue Feb 9, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@EOssesFrazoni
Copy link

TestRail CLI Version

1.4.0

CLI Environment

Windows 10 E 21H2 x64, Python 3.9.5

TestRail Version

TestRail v7.8.0 Default (1136)

TestRail Instance Type

Enterprise Cloud

Current behavior

TRCLI fails to generate or update TestCases with the error:
"AttributeError: 'TestRailCase' object has no attribute 'result_fields'" even when not using the optional parameter

This worked on previous version.

Command:
trcli -h "https://company.testrail.net/" -u "user@company.com" -p "api_key" --project "Project Name" --project-id 1 -y parse_junit --title "Pytest POC Suite" --run-description "Pytest POC Suite" -f "junit-report.xml" --case-fields custom_automation_type:3 --case-matcher "name"

CLI Output:

TestRail CLI v1.4.0
Copyright 2021 Gurock Software GmbH - www.gurock.com
Parse JUnit Execution Parameters
> Report file: junit-report.xml
> Config file: None
> TestRail instance: https://company.testrail.net (user: user@company.com)
> Project: PROJECT NAME
> Run title: Pytest POC Suite
> Update run: No
> Add to milestone: No
> Auto-create entities: True
Parsing JUnit report.
Processing suite - None
Processed 5 test cases in 1 sections.
Checking project. Done.
Found 5 test cases without case ID in the report file.
Adding missing test cases to the suite.
Traceback (most recent call last):
  File "c:\users\username\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\username\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\Scripts\trcli.exe\__main__.py", line 7, in <module>
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\commands\cmd_parse_junit.py", line 92, in cli
    result_uploader.upload_results()
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\api\results_uploader.py", line 94, in upload_results
    added_test_cases, result_code = self.add_missing_test_cases()
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\api\results_uploader.py", line 287, in add_missing_test_cases
    added_cases, result_code = self.prompt_user_and_add_items(
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\api\results_uploader.py", line 311, in prompt_user_and_add_items
    added_items, error_message = add_function()
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\api\api_request_handler.py", line 341, in add_cases
    add_case_data = self.data_provider.add_cases()
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\data_providers\api_data_provider.py", line 40, in add_cases
    case.add_global_case_fields(self.case_fields)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\trcli\data_classes\dataclass_testrail.py", line 150, in add_global_case_fields
    new_results_fields.update(self.result_fields)
AttributeError: 'TestRailCase' object has no attribute 'result_fields'

Desired behavior

Test Cases are updated or created in TestRail

More Details

No response

@EOssesFrazoni EOssesFrazoni added the bug Something isn't working label Feb 9, 2023
@d-rede
Copy link
Contributor

d-rede commented Feb 9, 2023

Hello @EOssesFrazoni

Thank you for bringing this to our attention. The bug fix has just been released in v1.4.1, which should be available in a few minutes via PyPI.

@EOssesFrazoni
Copy link
Author

Hi @d-rede. It is fixed now, it is creating new test cases but I see two issues:

  • It always creates duplicated test cases, even when they have the same name (and have been created by the same TRCLI)
  • When running with an existing Run Id (using --run-id), it tries to create the test cases again, then it deletes all and finishes with this error:
    Field :results contains one or more invalid results (case C863106 unknown or not part of the test run)
    I just want to update a TestRun with a new set of results for existing test cases.
    Note: the Run Id I passed as an argument was created by the a previous TRCLI run.

@d-rede
Copy link
Contributor

d-rede commented Feb 9, 2023

Hello again,

It always creates duplicated test cases, even when they have the same name (and have been created by the same TRCLI)

The --case-matcher name actually doesn't match the cases by name. It expects you to have the ID of the TestRail case in the name of the test instead. You can read more about it in the TestRail CLI - Specification first documentation. We recommend that you don't use the automatic test case creation if you are using the name/property matcher.

When running with an existing Run Id (using --run-id), it tries to create the test cases again, then it deletes all and finishes with this error:
Field :results contains one or more invalid results (case C863106 unknown or not part of the test run)
I just want to update a TestRun with a new set of results for existing test cases.
Note: the Run Id I passed as an argument was created by the a previous TRCLI run.

When using the --run-id to update a run, it is expected that you will be submitting results for the same tests. If you use the name/property matcher and don't have your TestRail case IDs in your automation code, new tests will be created and won't match the existing tests in the given test run. Once again, we discourage using automatic test creation (-y) if you use the name/property matcher.

@EOssesFrazoni
Copy link
Author

I didn't specify it but In my attempts I tried with and without the case-matcher parameter.
I've tried multiple combinations in the CLI but I'm still not able to do what I expect (adding test results for existing test cases in an existing test run).
If I use the run-id without case-matcher and Auto-create entities: False, but I still can get it working.
I'm expecting to use the first mechanism; "Using Automation ID"

command:
trcli -h "https://host/" -u "user@company.com" -p "key" --project "Project Name" --project-id 1 -n parse_junit --title "Pytest POC Suite" --run-description "Pytest POC Suite" -f "result.xml" --case-fields custom_automation_type:1 --run-id 11197

Test Run 11197 contains the a test case with the same name from my result.xml

This is the result:
`TestRail CLI v1.4.1
Copyright 2021 Gurock Software GmbH - www.gurock.com
Parse JUnit Execution Parameters

Report file: result.xml
Config file: None
TestRail instance: https://host.net/ (user: mail@company.com)
Project: Existing Project
Run title: Pytest POC Suite
Update run: 11197
Add to milestone: No
Auto-create entities: False
Parsing JUnit report.
Processing suite - None
Processed 1 test cases in 1 sections.
Checking project. Done.
Found 1 test cases not matching any TestRail case.
Updating run: https://host/index.php?/runs/view/11197
Adding results: 0/0, Done.
No attachments found to upload.`

@d-rede
Copy link
Contributor

d-rede commented Feb 9, 2023

If you use the automation ID, you should see how matching happens in this article: TestRail CLI - Code first documentation. It matches a custom field named automation_id, not the actual test name. When test cases are automatically created using the default --case-matcher auto, the automation_id is added to later be able to map the results to the correct test cases and not duplicate them.

@d-rede d-rede closed this as completed Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants