コード例 #1
0
def test_addmarker_order():
    node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
    node.add_marker("a")
    node.add_marker("b")
    node.add_marker("c", append=False)
    extracted = [x.name for x in node.iter_markers()]
    assert extracted == ["c", "a", "b"]
コード例 #2
0
ファイル: test_mark.py プロジェクト: yaswanthturner/pytest
def test_addmarker_order():
    session = mock.Mock()
    session.own_markers = []
    session.parent = None
    session.nodeid = ""
    node = Node.from_parent(session, name="Test")
    node.add_marker("foo")
    node.add_marker("bar")
    node.add_marker("baz", append=False)
    extracted = [x.name for x in node.iter_markers()]
    assert extracted == ["baz", "foo", "bar"]
コード例 #3
0
    def get_scope_node(
        node: nodes.Node, scope: Union[scope_.Scope, DistributedScope]
    ) -> Optional[Union[nodes.Item, nodes.Collector]]:
        import _pytest.python

        if scope is scope_.Scope.Function:
            return node.getparent(nodes.Item)
        elif scope is scope_.Scope.Class:
            return node.getparent(_pytest.python.Class)
        elif scope is scope_.Scope.Module:
            return node.getparent(_pytest.python.Module)
        elif scope is scope_.Scope.Package:
            return node.getparent(_pytest.python.Package)
        elif scope in [
                scope_.Scope.Session, DistributedScope.Node,
                DistributedScope.Global
        ]:
            return node.getparent(_pytest.main.Session)
        else:
            assert_never(scope)
コード例 #4
0
ファイル: test_mark.py プロジェクト: bronsen/pytest
def test_addmarker_order():
    node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
    node.add_marker("a")
    node.add_marker("b")
    node.add_marker("c", append=False)
    extracted = [x.name for x in node.iter_markers()]
    assert extracted == ["c", "a", "b"]
コード例 #5
0
ファイル: test_pytest_plugin.py プロジェクト: undera/apiritif
    def test_flow_maxdetail(self):
        tmp = tempfile.NamedTemporaryFile()
        tmp.close()
        config = ctype(otype(tmp.name, 3), PytestPluginManager())
        plugin = ApiritifPytestPlugin(config)
        for _ in plugin.pytest_runtest_setup(None):
            pass

        with apiritif.transaction("tran") as tran:
            tran.set_request(bytes("test", 'utf8'))

        node = Node("test", nodeid="tst", config=config, session="some")
        for _ in plugin.pytest_runtest_teardown(node):
            pass

        plugin.pytest_sessionfinish(None)

        with open(tmp.name) as fp:
            data = json.load(fp)

        self.assertNotEqual({}, data)
コード例 #6
0
def fake_process(trace_fname):
    config = ctype(otype(trace_fname, 4), PytestPluginManager(),
                   lambda x, y: 0)
    plugin = ApiritifPytestPlugin(config)
    next(plugin.pytest_runtest_setup(None))

    yield

    node = Node._create("test", nodeid="tst", config=config, session="some")
    node._report_sections = []
    node.location = []
    node.user_properties = []
    call = CallInfo.from_call(lambda: 1, 'call')
    report = TestReport.from_item_and_call(node, call)
    result = _Result(report, None)
    gen = plugin.pytest_runtest_makereport(node, call)
    next(gen)
    try:
        gen.send(result)
    except StopIteration:
        pass

    plugin.pytest_sessionfinish(None)
コード例 #7
0
    def test_flow_maxdetail(self):
        tmp = tempfile.NamedTemporaryFile()
        tmp.close()
        config = ctype(otype(tmp.name, 4), PytestPluginManager())
        plugin = ApiritifPytestPlugin(config)
        for _ in plugin.pytest_runtest_setup(None):
            pass

        with apiritif.transaction("tran") as tran:
            tran.set_request(bytes("test", 'utf8'))

        http.post('http://httpbin.org/post', data=bytes([0xa0, 1, 2, 3]),
                  headers={'Content-Type': 'application/octet-stream'})

        node = Node("test", nodeid="tst", config=config, session="some")
        for _ in plugin.pytest_runtest_teardown(node):
            pass

        plugin.pytest_sessionfinish(None)

        with open(tmp.name) as fp:
            data = json.load(fp)

        self.assertNotEqual({}, data)
コード例 #8
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]'
コード例 #9
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]"
コード例 #10
0
def test_addmarker_getmarker():
    node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
    node.add_marker(pytest.mark.a(1))
    node.add_marker("b")
    node.get_marker("a").combined
    node.get_marker("b").combined
コード例 #11
0
ファイル: test_mark.py プロジェクト: Coder206/servo
def test_addmarker_getmarker():
    node = Node("Test", config=mock.Mock(), session=mock.Mock(), nodeid="Test")
    node.add_marker(pytest.mark.a(1))
    node.add_marker("b")
    node.get_marker("a").combined
    node.get_marker("b").combined