def pytest_collection(session: pytest.Session): session.items = [] for filename, tests in groupby(coordinator.tests, key=lambda test: test['file']): file = MochaFile.from_parent(session, fspath=LocalPath(filename)) for info in tests: requested_fixtures = ['live_server', '_live_server_helper'] test = MochaTest.from_parent( file, name='::'.join(info['parents']), fixtureinfo=FuncFixtureInfo( argnames=tuple(requested_fixtures), initialnames=tuple(requested_fixtures), names_closure=requested_fixtures, name2fixturedefs={}, ), keywords={ 'django_db': pytest.mark.django_db(transaction=True), } ) session.items.append(test) ### # NOTE: if this counter remains 0 at end of session, an exit code of 5 will be returned. # This value is normally set by Session.perform_collect(), but we are bypassing that # implementation. # session.testscollected = len(session.items) return session.items
def request_fixtures(self, names): # pytest fixtures dance: fm = self.session._fixturemanager closure = fm.getfixtureclosure(names, self) try: initialnames, names_closure, arg2fixturedefs = closure except ValueError: # pragma: no cover # pytest < 3.7 names_closure, arg2fixturedefs = closure fixtureinfo = FuncFixtureInfo(names, names_closure, arg2fixturedefs) else: # pyest >= 3.7 fixtureinfo = FuncFixtureInfo(names, initialnames, names_closure, arg2fixturedefs) self._fixtureinfo = fixtureinfo self.funcargs = {} self._request = fixtures.FixtureRequest(self)
def pytest_collection(session: pytest.Session): session.items = [] for filename, tests in groupby(coordinator.tests, key=lambda test: test['file']): file = MochaFile( filename, parent=session, config=session.config, session=session, ) for info in tests: requested_fixtures = ['live_server', '_live_server_helper'] test = MochaTest( name='::'.join(info['parents']), parent=file, fixtureinfo=FuncFixtureInfo( argnames=tuple(requested_fixtures), initialnames=tuple(requested_fixtures), names_closure=requested_fixtures, name2fixturedefs={}, ), keywords={ 'django_db': pytest.mark.django_db(transaction=True), } ) session.items.append(test) return session.items
def request_fixtures(self, names): # pytest fixtures dance: fm = self.session._fixturemanager names_closure, arg2fixturedefs = fm.getfixtureclosure(names, self) fixtureinfo = FuncFixtureInfo(names, names_closure, arg2fixturedefs) self._fixtureinfo = fixtureinfo self.funcargs = {} self._request = fixtures.FixtureRequest(self)
def getfixtureinfo(self, node, func, cls, *, argnames): usefixtures = itertools.chain.from_iterable( mark.args for mark in node.iter_markers(name="usefixtures") ) initialnames = tuple(usefixtures) + tuple(argnames) fm = node.session._fixturemanager initialnames, names_closure, arg2fixturedefs = fm.getfixtureclosure( initialnames, node, ignore_args=self._get_direct_parametrize_args(node) ) return FuncFixtureInfo( tuple(argnames), initialnames, names_closure, arg2fixturedefs )