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

Unittest discovery using the new test adapter #18253

Merged
merged 98 commits into from
Apr 13, 2022

Conversation

kimadeline
Copy link

@kimadeline kimadeline commented Jan 7, 2022

For #17242

Known issues

  • Does not write in the Python test log output channel
  • If unittestEnabled is switched to false, does not remove the folder from the test view
  • Only unit tests
  • TS tests do not cover the test tree update logic yet
  • UX when using Python 2.7 not implemented yet

Important TS classes and functions

The tl;dr of the architecture is:

Test UI ↔️ PythonTestController (+ PythonTestServer) ↔️ WorkspaceTestAdapter ↔️ UnittestTestDiscoveryAdapter ↔️ Python side

And this PR introduces all the items in italics.

PythonTestServer (src/client/testing/testController/common/server.ts)

Server for the client-server communication that implements the ITestServer interface. This server gets instantiated by the PythonTestController class, and will stay alive for the duration of the session. It exposes a sendCommand method that will send the test command, wait for a reply from the Python script, and emit an event with the response if the data comes from a trusted source (we use uuids for that). It is up to the event listeners to parse this data into a JSON object if the data cwd matches the workspace's uri.

UnittestTestDiscoveryAdapter (src/client/testing/testController/unittest/testDiscoveryAdapter.ts)

Wrapper class for unittest that implements the ITestDiscoveryAdapter interface. It only does one thing: unittest test discovery, and is the one that will call PythonTestServer.sendCommand.

WorkspaceTestAdapter (src/client/testing/testController/workspaceTestAdapter.ts)

The biggest chunk of logic in this PR.

This class exposes a test-provider-agnostic way of discovering tests. It gets instantiated by the PythonTestController class in charge of reflecting test data in the UI (one instance per workspace), and then instantiates a UnittestTestDiscoveryAdapter under the hood depending on settings. Later on it will also support a PytestTestDiscoveryAdapter, and adapters for running and debugging tests.

This class formats the JSON test data returned by the UnittestTestDiscoveryAdapter into test UI elements, and uses them to insert/update/remove items in the TestController instance behind the testing UI whenever the PythonTestController requests a refresh.

@kimadeline kimadeline added the no-changelog No news entry required label Jan 7, 2022
@kimadeline kimadeline added this to the January 2022 milestone Jan 7, 2022
@kimadeline kimadeline self-assigned this Jan 7, 2022
@kimadeline kimadeline removed the no-changelog No news entry required label Jan 7, 2022
kimadeline and others added 2 commits February 1, 2022 12:05
Co-authored-by: Brett Cannon <brett@python.org>
@kimadeline
Copy link
Author

@karthiknadig @brettcannon I believe I addressed your comments, please come back for a third round of reviews 🥺



class TestNode(TestData):
children: "List[TestNode | TestItem]"
Copy link
Member

Choose a reason for hiding this comment

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

No need to make a change, but another way to deal with the forward references is to start the file with from __future__ import annotations, then you can ditch the quotes as Python will make all type annotations be strings.

@kimadeline kimadeline changed the title WIP - unittest discovery using the new test adapter Unittest discovery using the new test adapter Feb 24, 2022
@kimadeline kimadeline mentioned this pull request Feb 24, 2022
22 tasks
@brettcannon brettcannon modified the milestones: March 2022, April 2022 Mar 21, 2022
@kimadeline kimadeline merged commit 854ef00 into microsoft:main Apr 13, 2022
@kimadeline kimadeline deleted the 17242-unittest-discovery branch April 13, 2022 20:29
wesm pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
…n#18253)

* Basic test discovery (no server yet)

* Clean up test discovery script

* Add default test results array value (py side)

* Add localization

* Build tree on the Python side + move utils out

* Basic test discovery

* Add test tree update support

* Multiroot workspace support

* Make sure we don't shadow the "type" keyword

* Move discovery in a function

* Use pathlib everywhere

* News entry

* Add docstrings to utils tests + fix nested case

* Rename utils tests data + delete unused files

* Discovery tests

* Update comments + requirements

* Do not run test discovery for now

* Re-generate requirements using python 3.7

* Sort Python imports on save

* Get new server architecture up

* Add comment for tornado

* Apply Python suggestions from code review

Co-authored-by: Brett Cannon <brett@python.org>

* Pass test discovery adapter to workspace adapter

* Wrap nodes under test provider

* Let the OS pick a port

* traceLog when response processing errors out

Co-authored-by: Brett Cannon <brett@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants