File: test_using_pytest.py

package info (click to toggle)
python-noseofyeti 2.4.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: python: 2,581; sh: 31; makefile: 12
file content (84 lines) | stat: -rw-r--r-- 2,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import shutil
import subprocess
import sys
from pathlib import Path
from textwrap import dedent

here = Path(__file__).parent


class TestPyTest:
    def test_it_collects_tests_correctly(self, tmp_path_factory, monkeypatch):

        directory = tmp_path_factory.mktemp("files")

        monkeypatch.setenv("NOSE_OF_YETI_BLACK_COMPAT", "false")

        shutil.copytree(here / "for_pytest_plugin", directory / "tests")

        want = set(
            dedent(
                """
            tests/test_one.py::test_one
            tests/test_one.py::TestTwo::test_three
            tests/test_one.py::TestTwo::test_four
            tests/test_one.py::TestTwo_Five::test_six
            tests/test_one.py::TestTwo_Seven_Ten::test_eight
            tests/test_one.py::TestTwo_Seven_Ten::test_nine
            tests/test_one.py::TestTwo_Seven_Eleven::test_eight
            tests/test_one.py::TestTwo_Seven_Eleven::test_nine
            tests/test_one.py::TestTwelve::test_thirteen
            tests/test_two.py::TestOne::test_two
            tests/test_two.py::TestOne::test_three
            tests/test_two.py::TestOne::test_four
            tests/test_two.py::TestOne::test_five
            tests/test_two.py::TestOne_Six::test_seven
            tests/test_two.py::TestOne_Eight::test_nine
            tests/test_two.py::TestOne_Ten::test_eleven
            """
            )
            .strip()
            .split("\n")
        )

        with subprocess.Popen(
            [
                sys.executable,
                "-m",
                "pytest",
                str(directory / "tests" / "test_one.py"),
                str(directory / "tests" / "test_two.py"),
                "-v",
                "-o",
                "console_output_style=short",
            ],
            cwd=directory,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
        ) as process:
            try:
                process.wait(timeout=5)
            except:
                process.kill()
                raise

            out = process.stdout.read().decode()

            got = set()
            for line in out.split("\n"):
                if "PASSED" in line:
                    got.add(line.split(" ", 1)[0])

            print(out)

            print("WANT:")
            for line in sorted(want):
                print("  ", line)

            print()
            print("GOT:")
            for line in sorted(got):
                print("  ", line)

            assert "16 passed" in out
            assert got == want