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

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

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

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

    @scenario('foo_bar.feature', 'Foo bar')
    def test_foo():
        pass
    ''')
Example #2
0
def test_migrate(monkeypatch, capsys, testdir):
    """Test if the code is migrated by a given file mask."""
    tests = testdir.mkpydir('tests')

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

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

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

    @scenario('foo_bar.feature', 'Foo bar')
    def test_foo():
        pass
    ''')
Example #3
0
def test_main(monkeypatch, capsys):
    """Test if main command shows help when called without the subcommand."""
    monkeypatch.setattr(sys, "argv", ["pytest-bdd"])
    monkeypatch.setattr(sys, "exit", lambda x: x)
    main()
    out, err = capsys.readouterr()
    assert "usage: pytest-bdd [-h]" in err
    assert "pytest-bdd: error:" in err
Example #4
0
def test_main(monkeypatch, capsys):
    """Test if main commmand shows help when called without the subcommand."""
    monkeypatch.setattr(sys, 'argv', ['pytest-bdd'])
    monkeypatch.setattr(sys, 'exit', lambda x: x)
    main()
    out, err = capsys.readouterr()
    assert 'usage: pytest-bdd [-h]' in err
    assert 'pytest-bdd: error:' in err
Example #5
0
def test_generate(monkeypatch, capsys):
    """Test if the code is generated by a given feature."""
    monkeypatch.setattr(sys, "argv", ["", "generate", os.path.join(PATH, "generate.feature")])
    main()
    out, err = capsys.readouterr()
    assert out == textwrap.dedent(
        '''
    # coding=utf-8
    """Code generation feature tests."""

    from pytest_bdd import (
        given,
        scenario,
        then,
        when,
    )


    @scenario('scripts/generate.feature', 'Given and when using the same fixture should not evaluate it twice')
    def test_given_and_when_using_the_same_fixture_should_not_evaluate_it_twice():
        """Given and when using the same fixture should not evaluate it twice."""


    @given('1 have a fixture (appends 1 to a list) in reuse syntax')
    def have_a_fixture_appends_1_to_a_list_in_reuse_syntax():
        """1 have a fixture (appends 1 to a list) in reuse syntax."""
        raise NotImplementedError


    @given('I have an empty list')
    def i_have_an_empty_list():
        """I have an empty list."""
        raise NotImplementedError


    @when('I use this fixture')
    def i_use_this_fixture():
        """I use this fixture."""
        raise NotImplementedError


    @then('my list should be [1]')
    def my_list_should_be_1():
        """my list should be [1]."""
        raise NotImplementedError

    '''[
            1:
        ].replace(
            u"'", u"'"
        )
    )
Example #6
0
def test_generate(monkeypatch, capsys):
    """Test if the code is generated by a given feature."""
    monkeypatch.setattr(sys, 'argv', ['', 'generate', os.path.join(PATH, 'generate.feature')])
    main()
    out, err = capsys.readouterr()
    assert out == textwrap.dedent('''
    # coding=utf-8
    """Code generation feature tests."""

    from pytest_bdd import (
        given,
        scenario,
        then,
        when,
    )


    @scenario('scripts/generate.feature', 'Given and when using the same fixture should not evaluate it twice')
    def test_given_and_when_using_the_same_fixture_should_not_evaluate_it_twice():
        """Given and when using the same fixture should not evaluate it twice."""


    @given('1 have a fixture (appends 1 to a list) in reuse syntax')
    def have_a_fixture_appends_1_to_a_list_in_reuse_syntax():
        """1 have a fixture (appends 1 to a list) in reuse syntax."""
        raise NotImplementedError


    @given('I have an empty list')
    def i_have_an_empty_list():
        """I have an empty list."""
        raise NotImplementedError


    @when('I use this fixture')
    def i_use_this_fixture():
        """I use this fixture."""
        raise NotImplementedError


    @then('my list should be [1]')
    def my_list_should_be_1():
        """my list should be [1]."""
        raise NotImplementedError

    '''[1:].replace(u"'", u"'"))
Example #7
0
def test_generate(testdir, monkeypatch, capsys):
    """Test if the code is generated by a given feature."""

    features = testdir.mkdir("scripts")
    feature = features.join("generate.feature")
    feature.write_text(
        textwrap.dedent("""\
            Feature: Code generation

                Scenario: Given and when using the same fixture should not evaluate it twice
                    Given I have an empty list
                    And 1 have a fixture (appends 1 to a list) in reuse syntax

                    When I use this fixture

                    Then my list should be [1]
            """),
        "utf-8",
        ensure=True,
    )

    monkeypatch.setattr(sys, "argv", ["", "generate", feature.strpath])
    main()
    out, err = capsys.readouterr()
    assert out == textwrap.dedent('''\
    """Code generation feature tests."""

    from pytest_bdd import (
        given,
        scenario,
        then,
        when,
    )


    @scenario('scripts/generate.feature', 'Given and when using the same fixture should not evaluate it twice')
    def test_given_and_when_using_the_same_fixture_should_not_evaluate_it_twice():
        """Given and when using the same fixture should not evaluate it twice."""


    @given('1 have a fixture (appends 1 to a list) in reuse syntax')
    def have_a_fixture_appends_1_to_a_list_in_reuse_syntax():
        """1 have a fixture (appends 1 to a list) in reuse syntax."""
        raise NotImplementedError


    @given('I have an empty list')
    def i_have_an_empty_list():
        """I have an empty list."""
        raise NotImplementedError


    @when('I use this fixture')
    def i_use_this_fixture():
        """I use this fixture."""
        raise NotImplementedError


    @then('my list should be [1]')
    def my_list_should_be_1():
        """my list should be [1]."""
        raise NotImplementedError

    ''')