File: test_migrate.py

package info (click to toggle)
pytest-bdd 7.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 540 kB
  • sloc: python: 3,535; makefile: 134
file content (50 lines) | stat: -rw-r--r-- 1,138 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
"""Test code generation command."""

import os
import sys
import textwrap

from pytest_bdd.scripts import main

PATH = os.path.dirname(__file__)


def test_migrate(monkeypatch, capsys, pytester):
    """Test if the code is migrated by a given file mask."""
    tests = pytester.mkpydir("tests")

    tests.joinpath("test_foo.py").write_text(
        textwrap.dedent(
            '''
        """Foo bar tests."""
        from pytest_bdd import scenario

        test_foo = scenario('foo_bar.feature', 'Foo bar')
    '''
        )
    )

    monkeypatch.setattr(sys, "argv", ["", "migrate", str(tests)])
    main()
    out, err = capsys.readouterr()
    out = "\n".join(sorted(out.splitlines()))
    expected = textwrap.dedent(
        """
    migrated: {0}/test_foo.py
    skipped: {0}/__init__.py""".format(
            str(tests)
        )[
            1:
        ]
    )
    assert out == expected
    assert tests.joinpath("test_foo.py").read_text() == textwrap.dedent(
        '''
    """Foo bar tests."""
    from pytest_bdd import scenario

    @scenario('foo_bar.feature', 'Foo bar')
    def test_foo():
        pass
    '''
    )