Exemplo n.º 1
0
    def test_invalid_data_schema_raises_value_error(self):
        @fixture
        def foo(context, *args, **kwargs):
            pass

        class BadFixtureData(object):
            def __init__(self, fixture_func, *args, **kwargs):
                self.fixture_func = fixture_func
                self.fixture_args = args
                self.fixture_kwargs = kwargs

        fixture_registry = {
            "fixture.foo": BadFixtureData(foo, 1, 2, 3, name="foo_1")
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        with pytest.raises(ValueError) as exc_info:
            with scoped_context_layer(context):
                use_fixture_by_tag("fixture.foo", context, fixture_registry)

        # -- VERIFY:
        expected = "fixture_data: Expected tuple or fixture-func, but is:"
        assert expected in str(exc_info.value)
        assert "BadFixtureData object" in str(exc_info.value)
Exemplo n.º 2
0
    def test_data_schema2(self):
        @fixture
        def foo(context, *args, **kwargs):
            # -- NOTE checkpoints: Injected from outer scope.
            params = "%r, %r" % (args, kwargs)
            checkpoints.append("foo.setup: %s" % params)
            yield "fixture.foo"
            checkpoints.append("foo.cleanup: %s" % params)

        fixture_registry = {
            "fixture.foo": fixture_call_params(foo, 1, 2, 3, name="foo_1")
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        checkpoints = []
        with scoped_context_layer(context):
            use_fixture_by_tag("fixture.foo", context, fixture_registry)
            checkpoints.append("scoped-block")

        # -- VERIFY:
        assert checkpoints == [
            "foo.setup: (1, 2, 3), {'name': 'foo_1'}",
            "scoped-block",
            "foo.cleanup: (1, 2, 3), {'name': 'foo_1'}",
        ]
Exemplo n.º 3
0
    def test_data_schema2(self):
        @fixture
        def foo(context, *args, **kwargs):
            # -- NOTE checkpoints: Injected from outer scope.
            params = "%r, %r" % (args, kwargs)
            checkpoints.append("foo.setup: %s" % params)
            yield "fixture.foo"
            checkpoints.append("foo.cleanup: %s" % params)

        fixture_registry = {
            "fixture.foo": fixture_call_params(foo, 1, 2, 3, name="foo_1")
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        checkpoints = []
        with scoped_context_layer(context):
            use_fixture_by_tag("fixture.foo", context, fixture_registry)
            checkpoints.append("scoped-block")

        # -- VERIFY:
        assert checkpoints == [
            "foo.setup: (1, 2, 3), {'name': 'foo_1'}",
            "scoped-block",
            "foo.cleanup: (1, 2, 3), {'name': 'foo_1'}",
        ]
Exemplo n.º 4
0
    def test_invalid_data_schema_raises_value_error(self):
        @fixture
        def foo(context, *args, **kwargs):
            pass

        class BadFixtureData(object):
            def __init__(self, fixture_func, *args, **kwargs):
                self.fixture_func = fixture_func
                self.fixture_args = args
                self.fixture_kwargs = kwargs

        fixture_registry = {
            "fixture.foo": BadFixtureData(foo, 1, 2, 3, name="foo_1")
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        with pytest.raises(ValueError) as exc_info:
            with scoped_context_layer(context):
                use_fixture_by_tag("fixture.foo", context, fixture_registry)

        # -- VERIFY:
        expected = "fixture_data: Expected tuple or fixture-func, but is:"
        assert expected in str(exc_info.value)
        assert "BadFixtureData object" in str(exc_info.value)
Exemplo n.º 5
0
    def test_unknown_fixture_raises_lookup_error(self):
        fixture_registry = {}

        # -- PERFORM-TEST:
        context = make_runtime_context()
        with pytest.raises(LookupError) as exc_info:
            with scoped_context_layer(context):
                use_fixture_by_tag("UNKNOWN_FIXTURE", context, fixture_registry)

        # -- VERIFY:
        assert "Unknown fixture-tag: UNKNOWN_FIXTURE" in str(exc_info.value)
Exemplo n.º 6
0
    def test_unknown_fixture_raises_lookup_error(self):
        fixture_registry = {}

        # -- PERFORM-TEST:
        context = make_runtime_context()
        with pytest.raises(LookupError) as exc_info:
            with scoped_context_layer(context):
                use_fixture_by_tag("UNKNOWN_FIXTURE", context,
                                   fixture_registry)

        # -- VERIFY:
        assert "Unknown fixture-tag: UNKNOWN_FIXTURE" in str(exc_info.value)
Exemplo n.º 7
0
def before_tag(context, tag):
    '''
    call the fixture by the name of the tag
    '''
    log.debug(f'Entering environment.{sys._getframe(  ).f_code.co_name} for {tag=}')
    if tag.startswith(fixture_prefix):
        return use_fixture_by_tag(tag, context, FixtureRegistry)
    log.debug(f'Leaving environment.{sys._getframe(  ).f_code.co_name} for {tag=}')
Exemplo n.º 8
0
def selenium_browser(context):
    # Using the `fixture.browser` fixture should do a lookup on the config and return an appropriate
    # sub-fixture, e.g.: `fixture.browser.chrome`.
    browser = context.config.userdata.get("browser", "chrome").lower()
    fixture_tag = f"fixture.browser.{browser}"
    try:
        yield use_fixture_by_tag(fixture_tag, context, fixture_registry)
    except LookupError:
        raise ValueError(f"Unsupported browser option: {browser}")
Exemplo n.º 9
0
def before_tag(context, tag):
    """Modifies context based on encountered tags
	
	Description
	
	Args:
		context:	Behave testing context
		tag:		Decorator tag from a feature file
	"""
    if tag.startswith("fixture."):
        return use_fixture_by_tag(tag, context, tag_registry)
Exemplo n.º 10
0
def test_issue_767_use_feature_by_tag_has_no_return():
    """Verifies that issue #767 is fixed."""
    @fixture(name='fixture.foo')
    def foo_fixture(context, *args, **kwargs):
        context.foo = 'foo'
        return context.foo

    # -- SCHEMA 1: fixture_func
    fixture_registry1 = {"fixture.foo": foo_fixture}
    # -- SCHEMA 2: fixture_func, fixture_args, fixture_kwargs
    fixture_registry2 = {"fixture.foo": (foo_fixture, (), {})}

    context = Context(runner=Mock())
    fixture1 = use_fixture_by_tag("fixture.foo", context, fixture_registry1)
    assert fixture1 == "foo"
    assert context.foo is fixture1

    context = Context(runner=Mock())
    fixture2 = use_fixture_by_tag("fixture.foo", context, fixture_registry2)
    assert fixture2 == "foo"
    assert context.foo is fixture2
Exemplo n.º 11
0
def before_tag(context, tag):
    if tag.startswith('fixture'):
        fixtures = {
            'fixture.setup_testing_db_and_add_default_menu':
            (setup_testing_db_and_add_default_menu, ),
            'fixture.add_submenu':
            add_submenu,
        }

        pytest.set_trace()

        return use_fixture_by_tag(tag, context, fixtures)
Exemplo n.º 12
0
    def test_data_schema1(self):
        @fixture
        def foo(context, *args, **kwargs):
            # -- NOTE checkpoints: Injected from outer scope.
            checkpoints.append("foo.setup")
            yield "fixture:foo"
            checkpoints.append("foo.cleanup")

        fixture_registry = {
            "fixture.foo": foo,
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        checkpoints = []
        with scoped_context_layer(context):
            use_fixture_by_tag("fixture.foo", context, fixture_registry)
            checkpoints.append("scoped-block")

        # -- VERIFY:
        assert checkpoints == ["foo.setup", "scoped-block", "foo.cleanup"]
Exemplo n.º 13
0
    def test_data_schema1(self):
        @fixture
        def foo(context, *args, **kwargs):
            # -- NOTE checkpoints: Injected from outer scope.
            checkpoints.append("foo.setup")
            yield "fixture:foo"
            checkpoints.append("foo.cleanup")

        fixture_registry = {
            "fixture.foo": foo,
        }

        # -- PERFORM-TEST:
        context = make_runtime_context()
        checkpoints = []
        with scoped_context_layer(context):
            use_fixture_by_tag("fixture.foo", context, fixture_registry)
            checkpoints.append("scoped-block")

        # -- VERIFY:
        assert checkpoints == [
            "foo.setup", "scoped-block", "foo.cleanup"
        ]
Exemplo n.º 14
0
def before_tag(context, tag):
    # `@fixture` tags can be used to enable fixtures like web browsers and other resources required throughout the test.
    if tag.startswith("fixture."):
        return use_fixture_by_tag(tag, context, fixture_registry)
Exemplo n.º 15
0
def before_tag(context, tag):
    if tag.startswith("fixture."):
        use_fixture_by_tag(tag, context, FIXTURE_REGISTRY)
Exemplo n.º 16
0
def before_tag(context, tag):
    if tag.startswith("fixture."):
        return use_fixture_by_tag(tag, context, fixture_registry)
Exemplo n.º 17
0
def before_feature(context, feature):
    """ Function launch before each behave feature """
    DriverManager.create()
    for tag in feature.tags:
        if tag.startswith("fixture."):
            use_fixture_by_tag(tag, context, FIXTURES)
Exemplo n.º 18
0
def after_scenario(context, scenario):
    log('after %s -- %s' % (context.feature, context.scenario))
    use_fixture_by_tag(tag='fixture.test.fixture',
                       context=context,
                       fixture_registry=fixture_registry1)
Exemplo n.º 19
0
def before_tag(context, tag):
    if tag.startswith("fixture."):
        return use_fixture_by_tag(tag, context, fixture_registry)
def before_tag(context, tag):
    if tag == "fixture.browser.asker":
        return use_fixture_by_tag(tag, context, fixture_registry)
    elif tag == "fixture.browser.expert":
        return use_fixture_by_tag(tag, context, fixture_registry)