8
8
9
9
import pytest
10
10
11
- from .. import util
12
- from ..info import ParentInfo
11
+ from .. import util , discovery
13
12
from ._pytest_item import parse_item
14
13
15
14
@@ -63,7 +62,7 @@ class TestCollector(object):
63
62
64
63
def __init__ (self , tests = None ):
65
64
if tests is None :
66
- tests = DiscoveredTests ()
65
+ tests = discovery . DiscoveredTests ()
67
66
self ._tests = tests
68
67
self ._started = False
69
68
@@ -90,58 +89,3 @@ def pytest_collection_finish(self, session):
90
89
for item in items :
91
90
test , parents = parse_item (item , self .NORMCASE , self .PATHSEP )
92
91
self ._tests .add_test (test , parents )
93
-
94
-
95
- class DiscoveredTests (object ):
96
- """A container for the discovered tests and their parents."""
97
-
98
- def __init__ (self ):
99
- self .reset ()
100
-
101
- def __len__ (self ):
102
- return len (self ._tests )
103
-
104
- def __getitem__ (self , index ):
105
- return self ._tests [index ]
106
-
107
- @property
108
- def parents (self ):
109
- return sorted (self ._parents .values (), key = lambda v : (v .root or v .name , v .id ))
110
-
111
- def reset (self ):
112
- """Clear out any previously discovered tests."""
113
- self ._parents = {}
114
- self ._tests = []
115
-
116
- def add_test (self , test , parents ):
117
- """Add the given test and its parents."""
118
- parentid = self ._ensure_parent (test .path , parents )
119
- # Updating the parent ID and the test ID aren't necessary if the
120
- # provided test and parents (from the test collector) are
121
- # properly generated. However, we play it safe here.
122
- test = test ._replace (parentid = parentid )
123
- if not test .id .startswith ('.' + os .path .sep ):
124
- test = test ._replace (id = os .path .join ('.' , test .id ))
125
- self ._tests .append (test )
126
-
127
- def _ensure_parent (self , path , parents ):
128
- rootdir = path .root
129
-
130
- _parents = iter (parents )
131
- nodeid , name , kind = next (_parents )
132
- # As in add_test(), the node ID *should* already be correct.
133
- if nodeid != '.' and not nodeid .startswith ('.' + os .path .sep ):
134
- nodeid = os .path .join ('.' , nodeid )
135
- _parentid = nodeid
136
- for parentid , parentname , parentkind in _parents :
137
- # As in add_test(), the parent ID *should* already be correct.
138
- if parentid != '.' and not parentid .startswith ('.' + os .path .sep ):
139
- parentid = os .path .join ('.' , parentid )
140
- info = ParentInfo (nodeid , kind , name , rootdir , parentid )
141
- self ._parents [(rootdir , nodeid )] = info
142
- nodeid , name , kind = parentid , parentname , parentkind
143
- assert nodeid == '.'
144
- info = ParentInfo (nodeid , kind , name = rootdir )
145
- self ._parents [(rootdir , nodeid )] = info
146
-
147
- return _parentid
0 commit comments