Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,17 @@ def payload(cases: Generator[TestCase, None, None],
exs.append(ex)

count += len(cs)
return {"events": cs, "testRunner": test_runner, "group": group,
"noBuild": self.is_no_build, "metadata": get_env_values(client)}, exs
return {
"events": cs,
"testRunner": test_runner,
"group": group,
"metadata": get_env_values(client),
"noBuild": self.is_no_build,
# NOTE:
# testSuite and flavors are applied only when the no-build option is enabled
"testSuite": test_suite,
"flavors": flavor,
}, exs
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Undefined variables test_suite and flavor in payload function

The variables test_suite and flavor used in the payload dictionary are not defined within the scope of the payload function. This will result in a NameError when the function is executed.

To fix this issue, you can either pass test_suite and flavor as parameters to the payload function or access them as instance variables of the RecordTests class.

Solution 1: Pass test_suite and flavor as parameters

Modify the payload function signature to include test_suite and flavor, and update the calls to this function.

 def payload(cases: Generator[TestCase, None, None],
             test_runner, group: str,
+            test_suite: Optional[str], flavor: Sequence[Tuple[str, str]]) -> Tuple[Dict[str, Union[str, List, dict, bool]], List[Exception]]:
     # existing code
     return {
         "events": cs,
         "testRunner": test_runner,
         "group": group,
         "metadata": get_env_values(client),
         "noBuild": self.is_no_build,
         # NOTE:
         # testSuite and flavors are applied only when the no-build option is enabled
-        "testSuite": test_suite,
-        "flavors": flavor,
+        "testSuite": test_suite,
+        "flavors": flavor,
     }, exs

Update the calls to payload to include self.test_suite and self.flavor:

 # Within the run method
-    for chunk in ichunked(tc, post_chunk):
-        p, es = payload(chunk, test_runner, group)
+    for chunk in ichunked(tc, post_chunk):
+        p, es = payload(chunk, test_runner, group, self.test_suite, self.flavor)

Solution 2: Access test_suite and flavor as instance variables

Assign test_suite and flavor as instance variables in the RecordTests class and reference them using self in the payload function.

 # In the __init__ method of RecordTests, add parameters and assign to instance variables
 def __init__(self, dry_run=False,
+             test_suite: Optional[str] = None, flavor: Sequence[Tuple[str, str]] = ()):
     # existing code
     self.is_no_build = is_no_build
     self.metadata_builder = CaseEvent.default_data_builder()
+    self.test_suite = test_suite
+    self.flavor = flavor

 # In the payload function, reference instance variables
 def payload(cases: Generator[TestCase, None, None],
             test_runner, group: str) -> Tuple[Dict[str, Union[str, List, dict, bool]], List[Exception]]:
     # existing code
     return {
         "events": cs,
         "testRunner": test_runner,
         "group": group,
         "metadata": get_env_values(client),
         "noBuild": self.is_no_build,
         # NOTE:
         # testSuite and flavors are applied only when the no-build option is enabled
-        "testSuite": test_suite,
-        "flavors": flavor,
+        "testSuite": self.test_suite,
+        "flavors": self.flavor,
     }, exs

Ensure that you pass test_suite and flavor when instantiating RecordTests:

 # At the end of the tests function
-context.obj = RecordTests(dry_run=context.obj.dry_run)
+context.obj = RecordTests(dry_run=context.obj.dry_run, test_suite=test_suite, flavor=flavor)

Committable suggestion skipped: line range outside the PR's diff.


def send(payload: Dict[str, Union[str, List]]) -> None:
res = client.request(
Expand Down
4 changes: 3 additions & 1 deletion tests/data/ant/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
],
"testRunner": "ant",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/bazel/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,7 @@
],
"testRunner": "bazel",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
],
"testRunner": "bazel",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@
],
"testRunner": "bazel",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/behave/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
],
"testRunner": "behave",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/ctest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@
],
"testRunner": "ctest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/cts/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,7 @@
],
"testRunner": "cts",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/cucumber/record_test_json_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,7 @@
],
"testRunner": "cucumber",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/cucumber/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,7 @@
],
"testRunner": "cucumber",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/cypress/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@
],
"testRunner": "cypress",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/dotnet/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@
],
"testRunner": "dotnet",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/flutter/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
],
"testRunner": "flutter",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/go_test/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@
],
"testRunner": "go-test",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/googletest/fail/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
],
"testRunner": "googletest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/googletest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@
],
"testRunner": "googletest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/gradle/recursion/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@
],
"testRunner": "gradle",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/jest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,7 @@
],
"testRunner": "jest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/maven/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
],
"testRunner": "maven",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/minitest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,7 @@
],
"testRunner": "minitest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/nunit/nunit-reporter-bug-with-nested-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
],
"testRunner": "nunit",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/nunit/record_test_result-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@
],
"testRunner": "nunit",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/nunit/record_test_result-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@
],
"testRunner": "nunit",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/playwright/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -1677,5 +1677,7 @@
],
"testRunner": "playwright",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/playwright/record_test_result_with_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -2403,5 +2403,7 @@
],
"testRunner": "playwright",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/prove/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,7 @@
],
"testRunner": "prove",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/pytest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,7 @@
],
"testRunner": "pytest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/pytest/record_test_result_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@
],
"testRunner": "pytest",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
],
"testRunner": "robot",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/robot/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@
],
"testRunner": "robot",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
4 changes: 3 additions & 1 deletion tests/data/rspec/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,7 @@
],
"testRunner": "rspec",
"group": "",
"noBuild": false
"noBuild": false,
"flavors": [],
"testSuite": null
}
6 changes: 5 additions & 1 deletion tests/test_runners/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ def test_record_tests(self):
"testRunner": "raw",
"group": "",
"noBuild": False,
"flavors": [],
"testSuite": None,
})

@responses.activate
Expand Down Expand Up @@ -362,7 +364,9 @@ def test_record_tests_junit_xml(self):
],
"testRunner": "raw",
"group": "",
"noBuild": False
"noBuild": False,
"flavors": [],
"testSuite": None,
})

@responses.activate
Expand Down
Loading