Skip to content

feat(query): add --test-target filter for test items by parent target#1

Merged
silvi-t merged 1 commit intomainfrom
test-target
Apr 10, 2026
Merged

feat(query): add --test-target filter for test items by parent target#1
silvi-t merged 1 commit intomainfrom
test-target

Conversation

@silvi-t
Copy link
Copy Markdown
Contributor

@silvi-t silvi-t commented Mar 31, 2026

Summary

  • Adds --test-target CLI option to the query subcommand for filtering test items by parent test target name
  • Resolves the target name to a parent TEST item ID and filters results to only show items under that target
  • Useful for narrowing down query results in launches with multiple test targets (e.g. --test-target kuadrant)

Summary by CodeRabbit

  • New Features
    • Added a --test-target option to the query command to filter returned test items by parent test target name.
    • The specified test target is resolved and validated before a query runs; the command exits with an error if the target cannot be found.
    • Query results are further narrowed to include only items associated with the resolved parent test target.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 679a9596-ea2f-4f0f-b52b-b3a1786a8395

📥 Commits

Reviewing files that changed from the base of the PR and between 2f24c1c and 2786383.

📒 Files selected for processing (2)
  • src/reportportal/ap.py
  • src/reportportal/rp_query.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/reportportal/ap.py
  • src/reportportal/rp_query.py

📝 Walkthrough

Walkthrough

Added an optional CLI flag --test-target to the query subcommand; the handler resolves that test target name to a parent item ID via ReportPortal API, filters retrieved test items by that parent ID, and exits with code 1 if no matching test target is found.

Changes

Cohort / File(s) Summary
CLI Interface
src/reportportal/ap.py
Added optional --test-target argument to the query subcommand parser (str, default None).
Query Filtering Logic
src/reportportal/rp_query.py
Appended test_target=<value> to filter description when provided; added _resolve_test_target(client, launch_id, target_name) to find a TEST item and return its parent ID; run_query resolves test_target to parent_id, fails with exit code 1 if none found, and post-filters fetched items by item.get('parent') == parent_id when set.

Sequence Diagram

sequenceDiagram
    rect rgba(200,200,255,0.5)
    actor User
    end
    rect rgba(200,255,200,0.5)
    participant CLI
    participant QueryHandler
    participant APIClient
    end

    User->>CLI: Run `query` with --test-target
    CLI->>QueryHandler: Parse options (test_target)
    alt test_target provided
        QueryHandler->>APIClient: get_test_items(type='TEST', name=test_target)
        APIClient-->>QueryHandler: matching test items (or empty)
        alt match found
            QueryHandler->>QueryHandler: extract parent_id
            QueryHandler->>APIClient: get_test_items(for launch, other filters)
            APIClient-->>QueryHandler: returned items
            QueryHandler->>QueryHandler: filter items where item.parent == parent_id
            QueryHandler-->>CLI: return filtered items
        else no match
            QueryHandler-->>CLI: log error, exit code 1
        end
    else no test_target
        QueryHandler->>APIClient: get_test_items(for launch, other filters)
        APIClient-->>QueryHandler: returned items
        QueryHandler-->>CLI: return items
    end
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I sniffed the tests with eager feet,
Chased a target name down a logging street,
Found its parent, hopped through the gate,
Filtered the list — tidy and straight,
A carrot cheer for code complete! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarises the main change: adding a --test-target filter to the query subcommand for filtering test items by parent target.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-target

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@silvi-t silvi-t requested a review from zkraus March 31, 2026 13:02
@silvi-t silvi-t self-assigned this Mar 31, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/reportportal/rp_query.py (1)

505-517: Consider warning when --test-target is provided without a launch context.

If the user specifies --test-target without --launch-id or --launch-name, the filter is silently ignored since the code proceeds to list launches instead. This could be confusing for users who expect filtering to apply.

💡 Suggested improvement to warn users
     # Resolve test target to parent ID if specified
     test_target = getattr(options, 'test_target', None)
+    if test_target and not options.launch_id:
+        logger.warning("--test-target is only applicable when querying test items (requires --launch-id or --launch-name)")
     if test_target and options.launch_id:
         # Find the TEST item matching the target name
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/reportportal/rp_query.py` around lines 505 - 517, If a --test-target is
provided but no launch context is given, add a clear warning so the filter won't
be silently ignored: when reading test_target from options (variable
test_target) check if not (options.launch_id or options.launch_name) and emit
logger.warning stating that test_target filtering will be ignored unless a
launch (launch_id or launch_name) is provided; keep the existing branch that
resolves parent_id only when options.launch_id is present (the block using
client.get_test_items and parent_items) but ensure the warning is logged before
the code proceeds to list launches or otherwise continue.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/reportportal/rp_query.py`:
- Around line 532-535: The code filters 'items' when 'test_target' and
'parent_id' without first ensuring 'items' is not None, so move or add a guard
to check items is not None (the result of fetch_test_items()) before any
iteration; specifically, in the function handling fetch_test_items (where the
variables items, test_target, parent_id are used) ensure you test "if items is
None" and handle/return appropriately before performing the list comprehension
filtering (items = [item for item in items if item.get('parent') == parent_id])
so you never attempt to iterate over None.

---

Nitpick comments:
In `@src/reportportal/rp_query.py`:
- Around line 505-517: If a --test-target is provided but no launch context is
given, add a clear warning so the filter won't be silently ignored: when reading
test_target from options (variable test_target) check if not (options.launch_id
or options.launch_name) and emit logger.warning stating that test_target
filtering will be ignored unless a launch (launch_id or launch_name) is
provided; keep the existing branch that resolves parent_id only when
options.launch_id is present (the block using client.get_test_items and
parent_items) but ensure the warning is logged before the code proceeds to list
launches or otherwise continue.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48b270e1-7f9f-4732-b67b-373777836888

📥 Commits

Reviewing files that changed from the base of the PR and between 5aa0d16 and a1291c3.

📒 Files selected for processing (2)
  • src/reportportal/ap.py
  • src/reportportal/rp_query.py

Comment thread src/reportportal/rp_query.py Outdated
@github-project-automation github-project-automation Bot moved this to 🆕 New in Kuadrant QE Apr 1, 2026
@silvi-t silvi-t moved this from 🆕 New to In Review in Kuadrant QE Apr 1, 2026
@silvi-t silvi-t moved this to In Review in Kuadrant Apr 1, 2026
Copy link
Copy Markdown
Contributor

@zkraus zkraus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feature, please refactor/extract the code for getting the parent_id into reusable function, and please add notes for future code changes based on my poor design, see issue #2 .

Comment thread src/reportportal/rp_query.py Outdated
filters_desc = _build_filter_description(options)
filter_msg = f" with filters: {', '.join(filters_desc)}" if filters_desc else ""

# Resolve test target to parent ID if specified
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please refactor this part as its own function, and do just a function call here. Or maybe, move the call inside the if options.launch_id block line 519.

First I know this is originally my code, and I honestly have to say, it is a spaghetti code already. And structural refactoring is on the list. This would be a perfect beginning, of making the code more structured.

Comment thread src/reportportal/rp_query.py
Comment thread src/reportportal/rp_query.py Outdated
test_target = getattr(options, 'test_target', None)
if test_target and options.launch_id:
# Find the TEST item matching the target name
parent_items = client.get_test_items(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TODO comment here about rewriting it to fetch_test_item, once it supports additional filters.

you may link issue #2

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/reportportal/rp_query.py`:
- Around line 466-487: The return type annotation on _resolve_test_target is
incorrect: change its signature to return Optional[str] (not Optional[int]) and
ensure the variable parent_id and returned value remain strings as produced by
client.get_test_items (refer to _resolve_test_target, client.get_test_items and
parent_id); update the docstring return type description if present to reflect a
string parent item ID.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0712fdb0-5e75-45af-bd09-1288d2d1e3ca

📥 Commits

Reviewing files that changed from the base of the PR and between 06311ed and 2f24c1c.

📒 Files selected for processing (2)
  • src/reportportal/ap.py
  • src/reportportal/rp_query.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/reportportal/ap.py

Comment thread src/reportportal/rp_query.py Outdated
@silvi-t silvi-t requested a review from zkraus April 1, 2026 13:49
… name

Signed-off-by: silvi-t <silvinka.tarabova@gmail.com>
Copy link
Copy Markdown
Contributor

@zkraus zkraus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All points addressed, LGTM.

@silvi-t silvi-t merged commit f404e4a into main Apr 10, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to ✅ Done in Kuadrant QE Apr 10, 2026
@github-project-automation github-project-automation Bot moved this from In Review to Done in Kuadrant Apr 10, 2026
@silvi-t silvi-t deleted the test-target branch April 10, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants