Skip to content

typing: Session.__init__ #6525

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
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all 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
21 changes: 16 additions & 5 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@
import os
import sys
from typing import Dict
from typing import FrozenSet
from typing import List

import attr
import py

import _pytest._code
from _pytest import nodes
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.config import directory_arg
from _pytest.config import hookimpl
from _pytest.config import UsageError
from _pytest.fixtures import FixtureManager
from _pytest.nodes import Node
from _pytest.outcomes import exit
from _pytest.runner import collect_one_node
from _pytest.runner import SetupState


if TYPE_CHECKING:
from _pytest.python import Package


class ExitCode(enum.IntEnum):
"""
.. versionadded:: 5.0
Expand Down Expand Up @@ -383,7 +392,7 @@ class Session(nodes.FSCollector):
# Set on the session by fixtures.pytest_sessionstart.
_fixturemanager = None # type: FixtureManager

def __init__(self, config):
def __init__(self, config: Config) -> None:
nodes.FSCollector.__init__(
self, config.rootdir, parent=None, config=config, session=self, nodeid=""
)
Expand All @@ -394,14 +403,16 @@ def __init__(self, config):
self.trace = config.trace.root.get("collection")
self._norecursepatterns = config.getini("norecursedirs")
self.startdir = config.invocation_dir
self._initialpaths = frozenset()
self._initialpaths = frozenset() # type: FrozenSet[py.path.local]

# Keep track of any collected nodes in here, so we don't duplicate fixtures
self._node_cache = {}
self._node_cache = {} # type: Dict[str, List[Node]]
Copy link
Member

Choose a reason for hiding this comment

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

Apparently sometimes the key can be tuple so the type is not exactly correct:

pytest/src/_pytest/main.py

Lines 574 to 579 in ad02f6f

key = (type(x), x.fspath)
if key in self._node_cache:
yield self._node_cache[key]
else:
self._node_cache[key] = x
yield x

I am working on some annotations and will include a fix for this, hopefully tomorrow.

# Dirnames of pkgs with dunder-init files.
self._pkg_roots = {} # type: Dict[py.path.local, Package]

self._bestrelpathcache = _bestrelpath_cache(
config.rootdir
) # type: Dict[str, str]
# Dirnames of pkgs with dunder-init files.
self._pkg_roots = {}

self.config.pluginmanager.register(self, name="session")

Expand Down