How to use the pytest.mark.usefixtures function in pytest

To help you get started, we’ve selected a few pytest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Flexget / Flexget / tests / test_download.py View on Github external
"""Download plugin: Path and Temp directories set"""
        task = execute_task('path_and_temp')
        assert not task.aborted, 'Task should not have aborted'

    def test_just_path(self, execute_task):
        """Download plugin: Path directory set as dict"""
        task = execute_task('just_path')
        assert not task.aborted, 'Task should not have aborted'

    def test_just_string(self, execute_task):
        """Download plugin: Path directory set as string"""
        task = execute_task('just_string')
        assert not task.aborted, 'Task should not have aborted'


@pytest.mark.usefixtures('tmpdir')
class TestDownloadTemp(object):
    config = """
        tasks:
          temp_wrong_permission:
            mock:
              - {title: 'entry 1', url: 'http://www.speedtest.qsc.de/1kB.qsc'}
            accept_all: yes
            download:
              path: __tmp__
              temp: /root
          temp_non_existent:
            download:
              path: __tmp__
              temp: /a/b/c/non/existent/
          temp_wrong_config_1:
            download:
github karlch / vimiv-qt / tests / unit / gui / test_statusbar.py View on Github external
def test_statusbar_module():
    @statusbar.module("{simple}")
    def simple_module():
        return "text"
    assert statusbar.evaluate_modules("{simple}") == "text"


@pytest.fixture
def sb(qtbot):
    """Set up statusbar widget in qtbot."""
    sb = statusbar.StatusBar()
    qtbot.addWidget(sb)
    yield sb


@pytest.mark.usefixtures("cleansetup")
class TestStatusbar():

    def test_update_statusbar(self, mocker, sb):
        mocker.patch("vimiv.config.settings.get_value", return_value="text")
        sb.update()
        assert sb["left"].text() == "text"
        assert sb["center"].text() == "text"
        assert sb["right"].text() == "text"


    def test_update_statusbar_from_module(self, mocker, sb):
        mocker.patch.object(sb, "update")
        statusbar.update()
        sb.update.assert_called_once()
github tribe29 / checkmk / tests / unit / cmk / base / test_checks.py View on Github external
@pytest.mark.usefixtures("patch_mgmt_board_plugins")
@pytest.mark.parametrize("for_discovery,host_result,mgmt_board_result", [
    (False, ["snmp_check_host_only", "snmp_check_host_precedence"], ["snmp_check_mgmt_only"]),
    (True, ["snmp_check_host_only", "snmp_check_host_precedence"], ["snmp_check_mgmt_only"]),
])
def test_filter_by_management_board_SNMP_host_with_SNMP_mgmt_board(monkeypatch, for_discovery,
                                                                   host_result, mgmt_board_result):
    ts = Scenario()
    ts.add_host("this_host", tags={"snmp_ds": "snmp-v1", "agent": "no-agent"})
    config_cache = ts.apply(monkeypatch)
    h = config_cache.get_host_config("this_host")
    h.has_management_board = True

    found_check_plugins = set(c for c in _check_plugins() if c.startswith("snmp_"))
    monkeypatch.setattr(config, "check_info", found_check_plugins)

    assert config.filter_by_management_board("this_host",
github raiden-network / raiden-services / tests / pathfinding / test_graphs.py View on Github external
@pytest.mark.usefixtures("populate_token_network_case_3")
def test_reachability_mediator(
    token_network_model: TokenNetwork,
    reachability_state: SimpleReachabilityContainer,
    addresses: List[Address],
):

    assert get_paths(
        token_network_model=token_network_model,
        reachability_state=reachability_state,
        addresses=addresses,
    ) == [[0, 7, 8], [0, 1, 2, 3, 4, 8], [0, 7, 6, 8], [0, 7, 9, 10, 8], [0, 7, 6, 5, 8]]

    reachability_state.reachabilities[addresses[7]] = AddressReachability.UNREACHABLE
    assert get_paths(
        token_network_model=token_network_model,
        reachability_state=reachability_state,
github mapbox / tilesets-cli / tests / test_cli_delete.py View on Github external
@pytest.mark.usefixtures("token_environ")
@mock.patch("requests.Session.delete")
def test_cli_delete(mock_request_delete):
    runner = CliRunner()

    # sends expected request
    mock_request_delete.return_value = MockResponse("", status_code=200)
    result = runner.invoke(delete, ["test.id"], input="test.id")
    mock_request_delete.assert_called_with(
        "https://api.mapbox.com/tilesets/v1/test.id?access_token=fake-token"
    )
    assert result.exit_code == 0
    assert (
        result.output
        == 'To confirm tileset deletion please enter the full tileset id "test.id": test.id\nTileset deleted.\n'
    )
github fschulze / check-tls-certs / test_check_tls_certs.py View on Github external
@pytest.mark.usefixtures('no_chain_validation')
def test_expiration_far_in_future(makecert, utcnow):
    from check_tls_certs import Domain
    from check_tls_certs import check
    d = Domain('example.com')
    cert = makecert()
    (msgs, earliest_expiration) = check([(d, [cert])], utcnow)
    (msg,) = [m for m in msgs if m[1].startswith('Valid until')]
    assert '(364 days,' in msg[1]
    assert (earliest_expiration - utcnow).days == 364
github kvesteri / sqlalchemy-json-api / tests / test_select_one.py View on Github external
import json

import pytest


@pytest.mark.usefixtures('table_creator', 'dataset')
class TestSelectOne(object):
    def test_with_from_obj(self, query_builder, session, user_cls):
        query = query_builder.select_one(
            user_cls,
            1,
            fields={'users': ['all_friends']},
            from_obj=session.query(user_cls)
        )
        assert session.execute(query).scalar() == {
            'data': {
                'relationships': {
                    'all_friends': {'data': [{'id': '2', 'type': 'users'}]}
                },
                'id': '1',
                'type': 'users'
            }
github leapcode / soledad / tests / blobs / test_blob_manager.py View on Github external
    @pytest.mark.usefixtures("method_tmpdir")
    def test_delete_from_local_and_remote(self):
        self.manager._encrypt_and_upload = Mock(return_value=None)
        self.manager._delete_from_remote = Mock(return_value=None)
        content, blob_id = "Blob content", uuid4().hex
        doc1 = BlobDoc(BytesIO(content), blob_id)
        yield self.manager.put(doc1, len(content))
        yield self.manager.delete(blob_id)
        local_list = yield self.manager.local_list()
        self.assertEquals(0, len(local_list))
        params = {'namespace': ''}
        self.manager._delete_from_remote.assert_called_with(blob_id, **params)
github aerospike / aerospike-client-python / test / new_tests / test_query_predexp.py View on Github external
georec2 = {
            'id': 2,
            'point': geo_point2,
            'region': geo_object2,
            'geolist': [geo_point2]
        }

        as_connection.put(geok1, georec1)
        as_connection.put(geok2, georec2)

    yield

    as_connection.truncate('test', None, 0)


@pytest.mark.usefixtures('clean_test_demo_namespace')
class TestQueryPredexp(object):

    @pytest.fixture(autouse=True)
    def setup(self, request, as_connection):
        self.del_keys = []
        self.query = as_connection.query('test', 'demo')

    def test_integer_equals(self):
        predexps = [
            predexp.integer_bin('positive_i'),
            predexp.integer_value(5),
            predexp.integer_equal()
        ]
        self.query.predexp(predexps)
        results = self.query.results()
        assert len(results) == 1
github tribe29 / checkmk / tests / unit / cmk / base / data_sources / test_cmd_caching.py View on Github external
@pytest.mark.usefixtures("scenario")
@pytest.mark.usefixtures("patch_data_source_run")
def test_automation_diag_host_caching():
    args = ["ds-test-host1", "agent", "127.0.0.1", "", "6557", "10", "5", "5", ""]
    cmk.base.automations.check_mk.AutomationDiagHost().execute(args)
    assert ABCDataSource._run.call_count == 2  # type: ignore[attr-defined]