예제 #1
0
 def getpathnode(self, path):
     config = self.parseconfigure(path)
     session = Session(config)
     x = session.fspath.bestrelpath(path)
     config.hook.pytest_sessionstart(session=session)
     res = session.perform_collect([x], genitems=False)[0]
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return res
예제 #2
0
 def getnode(self, config, arg):
     session = Session(config)
     assert '::' not in str(arg)
     p = py.path.local(arg)
     config.hook.pytest_sessionstart(session=session)
     res = session.perform_collect([str(p)], genitems=False)[0]
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return res
예제 #3
0
 def getnode(self, config, arg):
     session = Session(config)
     assert "::" not in str(arg)
     p = py.path.local(arg)
     config.hook.pytest_sessionstart(session=session)
     res = session.perform_collect([str(p)], genitems=False)[0]
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return res
예제 #4
0
 def getpathnode(self, path):
     config = self.parseconfigure(path)
     session = Session(config)
     x = session.fspath.bestrelpath(path)
     config.hook.pytest_sessionstart(session=session)
     res = session.perform_collect([x], genitems=False)[0]
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return res
예제 #5
0
 def inline_genitems(self, *args):
     # config = self.parseconfig(*args)
     config = self.parseconfigure(*args)
     rec = self.getreportrecorder(config)
     session = Session(config)
     config.hook.pytest_sessionstart(session=session)
     session.perform_collect()
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return session.items, rec
예제 #6
0
 def inline_genitems(self, *args):
     #config = self.parseconfig(*args)
     config = self.parseconfigure(*args)
     rec = self.getreportrecorder(config)
     session = Session(config)
     config.hook.pytest_sessionstart(session=session)
     session.perform_collect()
     config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
     return session.items, rec
예제 #7
0
 def session_start(self):
     """Start a pytest session."""
     if self.config is None:
         self.start()
     self.config._do_configure()
     if hasattr(Session, "from_config"):
         self.session = Session.from_config(self.config)
     else:  # TODO remove with pytest >= 5.4
         self.session = Session(self.config)
     self.config.hook.pytest_sessionstart(session=self.session)
     # TODO remove this when it's fixed in IPython
     warnings.filterwarnings('ignore', module=r'^jedi\.cache')
예제 #8
0
def group_in_pytest(group):
    from _pytest.config import _prepareconfig
    from _pytest.main import Session
    from _pytest.python import FixtureManager
    from _pytest.mark import MarkMapping
    config = _prepareconfig(args="")
    session = Session(config)
    session._fixturemanager = FixtureManager(session)
    l = [list(MarkMapping(i.keywords)._mymarks) for i
         in session.perform_collect()]
    groups = set([item for sublist in l for item in sublist])

    return group in groups
예제 #9
0
 def test_collect_topdir(self, testdir):
     p = testdir.makepyfile("def test_func(): pass")
     id = "::".join([p.basename, "test_func"])
     # XXX migrate to collectonly? (see below)
     config = testdir.parseconfig(id)
     topdir = testdir.tmpdir
     rcol = Session(config)
     assert topdir == rcol.fspath
     #rootid = rcol.nodeid
     #root2 = rcol.perform_collect([rcol.nodeid], genitems=False)[0]
     #assert root2 == rcol, rootid
     colitems = rcol.perform_collect([rcol.nodeid], genitems=False)
     assert len(colitems) == 1
     assert colitems[0].fspath == p
예제 #10
0
 def test_collect_topdir(self, testdir):
     p = testdir.makepyfile("def test_func(): pass")
     id = "::".join([p.basename, "test_func"])
     # XXX migrate to inline_genitems? (see below)
     config = testdir.parseconfig(id)
     topdir = testdir.tmpdir
     rcol = Session(config)
     assert topdir == rcol.fspath
     rootid = rcol.nodeid
     #root2 = rcol.perform_collect([rcol.nodeid], genitems=False)[0]
     #assert root2 == rcol, rootid
     colitems = rcol.perform_collect([rcol.nodeid], genitems=False)
     assert len(colitems) == 1
     assert colitems[0].fspath == p
예제 #11
0
    def test_hook_proxy(self, testdir):
        """Test the gethookproxy function(#2016)"""
        config = testdir.parseconfig()
        session = Session(config)
        testdir.makepyfile(**{"tests/conftest.py": "", "tests/subdir/conftest.py": ""})

        conftest1 = testdir.tmpdir.join("tests/conftest.py")
        conftest2 = testdir.tmpdir.join("tests/subdir/conftest.py")

        config.pluginmanager._importconftest(conftest1)
        ihook_a = session.gethookproxy(testdir.tmpdir.join("tests"))
        assert ihook_a is not None
        config.pluginmanager._importconftest(conftest2)
        ihook_b = session.gethookproxy(testdir.tmpdir.join("tests"))
        assert ihook_a is not ihook_b
예제 #12
0
def group_in_pytest(group):
    from _pytest.config import _prepareconfig
    from _pytest.main import Session
    from _pytest.python import FixtureManager
    from _pytest.mark import MarkMapping
    config = _prepareconfig(args="")
    session = Session(config)
    session._fixturemanager = FixtureManager(session)
    l = [
        list(MarkMapping(i.keywords)._mymarks)
        for i in session.perform_collect()
    ]
    groups = set([item for sublist in l for item in sublist])

    return group in groups
예제 #13
0
    def test_hook_proxy(self, testdir):
        """Test the gethookproxy function(#2016)"""
        config = testdir.parseconfig()
        session = Session(config)
        testdir.makepyfile(**{"tests/conftest.py": "", "tests/subdir/conftest.py": ""})

        conftest1 = testdir.tmpdir.join("tests/conftest.py")
        conftest2 = testdir.tmpdir.join("tests/subdir/conftest.py")

        config.pluginmanager._importconftest(conftest1)
        ihook_a = session.gethookproxy(testdir.tmpdir.join("tests"))
        assert ihook_a is not None
        config.pluginmanager._importconftest(conftest2)
        ihook_b = session.gethookproxy(testdir.tmpdir.join("tests"))
        assert ihook_a is not ihook_b
예제 #14
0
파일: pytester.py 프로젝트: zx996/-cs1531
    def getpathnode(self, path):
        """Return the collection node of a file.

        This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
        create the (configured) pytest Config instance.

        :param path: a :py:class:`py.path.local` instance of the file

        """
        config = self.parseconfigure(path)
        session = Session(config)
        x = session.fspath.bestrelpath(path)
        config.hook.pytest_sessionstart(session=session)
        res = session.perform_collect([x], genitems=False)[0]
        config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
        return res
예제 #15
0
    def getpathnode(self, path):
        """Return the collection node of a file.

        This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
        create the (configured) pytest Config instance.

        :param path: a :py:class:`py.path.local` instance of the file

        """
        config = self.parseconfigure(path)
        session = Session(config)
        x = session.fspath.bestrelpath(path)
        config.hook.pytest_sessionstart(session=session)
        res = session.perform_collect([x], genitems=False)[0]
        config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
        return res
예제 #16
0
    def getnode(self, config, arg):
        """Return the collection node of a file.

        :param config: :py:class:`_pytest.orig.config.Config` instance, see
           :py:meth:`parseconfig` and :py:meth:`parseconfigure` to
           create the configuration.

        :param arg: A :py:class:`py.path.local` instance of the file.

        """
        session = Session(config)
        assert '::' not in str(arg)
        p = py.path.local(arg)
        config.hook.pytest_sessionstart(session=session)
        res = session.perform_collect([str(p)], genitems=False)[0]
        config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
        return res
예제 #17
0
    def make_function(pytester: Pytester, **kwargs: Any) -> Any:
        from _pytest.fixtures import FixtureManager

        config = pytester.parseconfigure()
        session = Session.from_config(config)
        session._fixturemanager = FixtureManager(session)

        return pytest.Function.from_parent(parent=session, **kwargs)
예제 #18
0
    def getnode(self, config, arg):
        """Return the collection node of a file.

        :param config: :py:class:`_pytest.config.Config` instance, see
           :py:meth:`parseconfig` and :py:meth:`parseconfigure` to
           create the configuration.

        :param arg: A :py:class:`py.path.local` instance of the file.

        """
        session = Session(config)
        assert '::' not in str(arg)
        p = py.path.local(arg)
        config.hook.pytest_sessionstart(session=session)
        res = session.perform_collect([str(p)], genitems=False)[0]
        config.hook.pytest_sessionfinish(session=session, exitstatus=EXIT_OK)
        return res
예제 #19
0
    def test_parsearg(self, testdir):
        p = testdir.makepyfile("def test_func(): pass")
        subdir = testdir.mkdir("sub")
        subdir.ensure("__init__.py")
        target = subdir.join(p.basename)
        p.move(target)
        subdir.chdir()
        config = testdir.parseconfig(p.basename)
        rcol = Session(config=config)
        assert rcol.fspath == subdir
        parts = rcol._parsearg(p.basename)

        assert parts[0] == target
        assert len(parts) == 1
        parts = rcol._parsearg(p.basename + "::test_func")
        assert parts[0] == target
        assert parts[1] == "test_func"
        assert len(parts) == 2
예제 #20
0
    def test_parsearg(self, testdir):
        p = testdir.makepyfile("def test_func(): pass")
        subdir = testdir.mkdir("sub")
        subdir.ensure("__init__.py")
        target = subdir.join(p.basename)
        p.move(target)
        subdir.chdir()
        config = testdir.parseconfig(p.basename)
        rcol = Session(config=config)
        assert rcol.fspath == subdir
        parts = rcol._parsearg(p.basename)

        assert parts[0] ==  target
        assert len(parts) == 1
        parts = rcol._parsearg(p.basename + "::test_func")
        assert parts[0] ==  target
        assert parts[1] ==  "test_func"
        assert len(parts) == 2
예제 #21
0
    def test_hook_proxy(self, pytester: Pytester) -> None:
        """Test the gethookproxy function(#2016)"""
        config = pytester.parseconfig()
        session = Session.from_config(config)
        pytester.makepyfile(**{"tests/conftest.py": "", "tests/subdir/conftest.py": ""})

        conftest1 = pytester.path.joinpath("tests/conftest.py")
        conftest2 = pytester.path.joinpath("tests/subdir/conftest.py")

        config.pluginmanager._importconftest(conftest1, importmode="prepend")
        ihook_a = session.gethookproxy(pytester.path / "tests")
        assert ihook_a is not None
        config.pluginmanager._importconftest(conftest2, importmode="prepend")
        ihook_b = session.gethookproxy(pytester.path / "tests")
        assert ihook_a is not ihook_b
예제 #22
0
def test_generic_path(testdir):
    from _pytest.main import Session
    config = testdir.parseconfig()
    session = Session(config)
    p1 = Node('a', config=config, session=session)
    #assert p1.fspath is None
    p2 = Node('B', parent=p1)
    p3 = Node('()', parent = p2)
    item = Item('c', parent = p3)

    res = generic_path(item)
    assert res == 'a.B().c'

    p0 = FSCollector('proj/test', config=config, session=session)
    p1 = FSCollector('proj/test/a', parent=p0)
    p2 = Node('B', parent=p1)
    p3 = Node('()', parent = p2)
    p4 = Node('c', parent=p3)
    item = Item('[1]', parent = p4)

    res = generic_path(item)
    assert res == 'test/a:B().c[1]'
예제 #23
0
def test_generic_path(testdir):
    from _pytest.main import Session

    config = testdir.parseconfig()
    session = Session(config)
    p1 = Node("a", config=config, session=session, nodeid="a")
    # assert p1.fspath is None
    p2 = Node("B", parent=p1)
    p3 = Node("()", parent=p2)
    item = Item("c", parent=p3)

    res = generic_path(item)
    assert res == "a.B().c"

    p0 = FSCollector("proj/test", config=config, session=session)
    p1 = FSCollector("proj/test/a", parent=p0)
    p2 = Node("B", parent=p1)
    p3 = Node("()", parent=p2)
    p4 = Node("c", parent=p3)
    item = Item("[1]", parent=p4)

    res = generic_path(item)
    assert res == "test/a:B().c[1]"
예제 #24
0
 def pytest_sessionfinish(self, session: Session, exitstatus: int) -> None:
     if exitstatus != 0 and self.known_failure_cases and not self.failed_cases:
         session.exitstatus = 0
예제 #25
0
def pytest_collection_modifyitems(session: Session, config, items: list):

    items.reverse()
    session.items = items
예제 #26
0
def pytest_collection_modifyitems(session: Session, config, items: list):
    # called after collection is completed
    # you can modify the ``items`` list
    # items.reverse()
    session.items = items
예제 #27
0
 def pytest_collection_finish(self, session: Session) -> None:
     session.items = self.service.filter_test_items(session.items)