Ejemplo n.º 1
0
    def test_stdio_not_hidden(self):
        pytest_stdout = 'spamspamspamspamspamspamspammityspam'
        stub = Stub()
        def fake_pytest_main(args, plugins):
            stub.add_call('pytest.main', None, {'args': args,
                                                'plugins': plugins})
            print(pytest_stdout, end='')
            return 0
        plugin = StubPlugin(stub)
        plugin.discovered = []
        buf = StringIO()

        sys.stdout = buf
        try:
            discover([], hidestdio=False,
                     _pytest_main=fake_pytest_main, _plugin=plugin)
        finally:
            sys.stdout = sys.__stdout__
        captured = buf.getvalue()

        self.assertEqual(captured, pytest_stdout)
        self.assertEqual(stub.calls, [
            ('pytest.main', None, {'args': self.DEFAULT_ARGS,
                                   'plugins': [plugin]}),
            ('discovered.parents', None, None),
            ('discovered.__len__', None, None),
            ('discovered.__getitem__', (0,), None),
            ])
Ejemplo n.º 2
0
    def test_failure(self):
        stub = Stub()
        pytest = StubPyTest(stub)
        pytest.return_main = 2
        plugin = StubPlugin(stub)

        with self.assertRaises(Exception):
            discover([], _pytest_main=pytest.main, _plugin=plugin)

        self.assertEqual(stub.calls, [
            ('pytest.main', None, {'args': self.DEFAULT_ARGS,
                                   'plugins': [plugin]}),
            ])
Ejemplo n.º 3
0
    def test_basic(self):
        stub = Stub()
        pytest = StubPyTest(stub)
        plugin = StubPlugin(stub)
        expected = []
        plugin.discovered = expected

        discovered = discover([], _pytest_main=pytest.main, _plugin=plugin)

        self.assertEqual(discovered, expected)
        self.assertEqual(stub.calls, [
            ('pytest.main', None, {'args': self.DEFAULT_ARGS,
                                   'plugins': [plugin]}),
            ])
Ejemplo n.º 4
0
    def test_basic(self):
        stub = Stub()
        stubpytest = StubPyTest(stub)
        plugin = StubPlugin(stub)
        expected = []
        plugin.discovered = expected

        parents, tests = discover([], _pytest_main=stubpytest.main, _plugin=plugin)

        self.assertEqual(parents, [])
        self.assertEqual(tests, expected)
        self.assertEqual(stub.calls, [
            ('pytest.main', None, {'args': self.DEFAULT_ARGS,
                                   'plugins': [plugin]}),
            ('discovered.parents', None, None),
            ('discovered.__len__', None, None),
            ('discovered.__getitem__', (0,), None),
            ])