forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix some problems in the pytest adapter. #5648
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
Merged
DonJayamanne
merged 13 commits into
microsoft:master
from
ericsnowcurrently:pytest-adapter-cleanup
Jun 18, 2019
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9c5e49a
Factor out _normalize_node_id().
ericsnowcurrently afb18e3
Find and handle item kind properly.
ericsnowcurrently e53462e
Factor out _iter_nodes().
ericsnowcurrently d78ff85
Return the parents from _parse_node_id().
ericsnowcurrently 80f790b
Return the parents from parse_item().
ericsnowcurrently 93d459f
Add a fix_path() testing helper.
ericsnowcurrently 0fe9c42
Pass the parents to add_test().
ericsnowcurrently 0c4ff21
Pass the parents to _ensure_parents().
ericsnowcurrently 0762284
Move DiscoveredTests out of the pytest code.
ericsnowcurrently 84255e9
Fix case on Windows.
ericsnowcurrently f6fb826
Add ShouldNeverReachHere exception type.
ericsnowcurrently 01bf922
Resolve all the TODO comments.
ericsnowcurrently a13dffb
Make ShouldNeverReachHere an informative function instead.
ericsnowcurrently File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import absolute_import, print_function | ||
|
|
||
| import os.path | ||
|
|
||
| from .info import ParentInfo | ||
|
|
||
|
|
||
|
|
||
| class DiscoveredTests(object): | ||
| """A container for the discovered tests and their parents.""" | ||
|
|
||
| def __init__(self): | ||
| self.reset() | ||
|
|
||
| def __len__(self): | ||
| return len(self._tests) | ||
|
|
||
| def __getitem__(self, index): | ||
| return self._tests[index] | ||
|
|
||
| @property | ||
| def parents(self): | ||
| return sorted(self._parents.values(), key=lambda v: (v.root or v.name, v.id)) | ||
|
|
||
| def reset(self): | ||
| """Clear out any previously discovered tests.""" | ||
| self._parents = {} | ||
| self._tests = [] | ||
|
|
||
| def add_test(self, test, parents): | ||
| """Add the given test and its parents.""" | ||
| parentid = self._ensure_parent(test.path, parents) | ||
| # Updating the parent ID and the test ID aren't necessary if the | ||
| # provided test and parents (from the test collector) are | ||
| # properly generated. However, we play it safe here. | ||
| test = test._replace(parentid=parentid) | ||
| if not test.id.startswith('.' + os.path.sep): | ||
| test = test._replace(id=os.path.join('.', test.id)) | ||
| self._tests.append(test) | ||
|
|
||
| def _ensure_parent(self, path, parents): | ||
| rootdir = path.root | ||
|
|
||
| _parents = iter(parents) | ||
| nodeid, name, kind = next(_parents) | ||
| # As in add_test(), the node ID *should* already be correct. | ||
| if nodeid != '.' and not nodeid.startswith('.' + os.path.sep): | ||
| nodeid = os.path.join('.', nodeid) | ||
| _parentid = nodeid | ||
| for parentid, parentname, parentkind in _parents: | ||
| # As in add_test(), the parent ID *should* already be correct. | ||
| if parentid != '.' and not parentid.startswith('.' + os.path.sep): | ||
| parentid = os.path.join('.', parentid) | ||
| info = ParentInfo(nodeid, kind, name, rootdir, parentid) | ||
| self._parents[(rootdir, nodeid)] = info | ||
| nodeid, name, kind = parentid, parentname, parentkind | ||
| assert nodeid == '.' | ||
| info = ParentInfo(nodeid, kind, name=rootdir) | ||
| self._parents[(rootdir, nodeid)] = info | ||
|
|
||
| return _parentid | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.