Skip to content
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

tests: fix/harden test_unittest_not_shown_in_traceback #476

Open
wants to merge 3 commits into
base: my-master
Choose a base branch
from
Open
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
56 changes: 35 additions & 21 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import gc

import pytest
from _pytest.compat import TYPE_CHECKING
from _pytest.config import ExitCode
from _pytest.pytester import Testdir

if TYPE_CHECKING:
from _pytest.pytester import Testdir

def test_simple_unittest(testdir):
testpath = testdir.makepyfile(

def test_simple_unittest(testdir: "Testdir") -> None:
p1 = testdir.makepyfile(
"""
import unittest
class MyTestCase(unittest.TestCase):
Expand All @@ -16,9 +19,34 @@ def test_failing(self):
self.assertEqual('foo', 'bar')
"""
)
reprec = testdir.inline_run(testpath)
assert reprec.matchreport("testpassing").passed
assert reprec.matchreport("test_failing").failed
result = testdir.runpytest(p1, "-rap")
result.stdout.fnmatch_lines(
[
"collected 2 items",
"",
"test_simple_unittest.py F. *",
"",
"=*= FAILURES =*=",
"_*_ MyTestCase.test_failing _*_",
"",
"self = <test_simple_unittest.MyTestCase testMethod=test_failing>",
"",
" def test_failing(self):",
"> self.assertEqual('foo', 'bar')",
"E AssertionError: 'foo' != 'bar'",
"E - foo",
"E + bar",
"",
"test_simple_unittest.py:6: AssertionError: 'foo' != 'bar'...",
"=*= short test summary info =*=",
"FAILED test_simple_unittest.py:6::MyTestCase::test_failing"
r" - AssertionError: 'foo' != 'bar'\n- foo\n+ bar",
"PASSED test_simple_unittest.py::MyTestCase::testpassing",
"=*= 1 failed, 1 passed in *s =*=",
],
consecutive=True,
)
assert result.ret == 1


def test_runTest_method(testdir):
Expand Down Expand Up @@ -692,20 +720,6 @@ def _post_teardown(self):
)


def test_unittest_not_shown_in_traceback(testdir):
testdir.makepyfile(
"""
import unittest
class t(unittest.TestCase):
def test_hello(self):
x = 3
self.assertEqual(x, 4)
"""
)
res = testdir.runpytest()
res.stdout.no_fnmatch_line("*failUnlessEqual*")


def test_unorderable_types(testdir):
testdir.makepyfile(
"""
Expand All @@ -726,7 +740,7 @@ class Test(unittest.TestCase):
assert result.ret == ExitCode.NO_TESTS_COLLECTED


def test_order(testdir: Testdir) -> None:
def test_order(testdir: "Testdir") -> None:
"""Test for unittest's behavior to sort tests by default (via TestLoader).

This could be made configurable maybe."""
Expand Down