How to use the pytest.mark 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 pytest-dev / pytest-forked / testing / test_boxed.py View on Github external
    pytest.param("fd", marks=pytest.mark.xfail(reason="capture cleanup needed"))])
def test_functional_boxed_capturing(testdir, capmode):
    p1 = testdir.makepyfile("""
        import os
        import sys
        def test_function():
            sys.stdout.write("hello\\n")
            sys.stderr.write("world\\n")
            os.kill(os.getpid(), 15)
    """)
    result = testdir.runpytest(p1, "--forked", "--capture=%s" % capmode)
    result.stdout.fnmatch_lines("""
        *CRASHED*
github hishnash / djangochannelsrestframework / tests / test_model_observer.py View on Github external
@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
async def test_observer_model_instance_mixin(settings):
    settings.CHANNEL_LAYERS={
        "default": {
            "BACKEND": "channels.layers.InMemoryChannelLayer",
            "TEST_CONFIG": {
                "expiry": 100500,
            },
        },
    }

    layer = channel_layers.make_test_backend(DEFAULT_CHANNEL_LAYER)

    class TestConsumer(ObserverModelInstanceMixin, GenericAsyncAPIConsumer):

        queryset = get_user_model().objects.all()
github koenvervloesem / snipskit / tests / test_services_integration.py View on Github external
"""Integration tests for the `snipskit.services` module.

This needs snips-dialogue and snips-nlu running, as well as mosquitto listening
on localhost:1883.
"""
import os
import subprocess
import time

import pytest

from snipskit.services import _version_output, is_installed, is_running, \
    model_version, installed, running, versions, version

# Only run these tests if the environment variable INTEGRATION_TESTS is set.
pytestmark = pytest.mark.skipif(not os.environ.get('INTEGRATION_TESTS'),
                                reason='Integration test')

@pytest.fixture
def snips_tts(mqtt_server):
    print('Starting Snips TTS')
    snips_tts = subprocess.Popen('snips-tts')
    time.sleep(1)  # Let's wait a bit before it's started
    yield snips_tts
    print('Tearing down Snips TTS')
    snips_tts.kill()

def test_version_output():
    """Test whether the `_version_output` function returns the right result."""

    # These services are installed
    assert _version_output('snips-dialogue') == 'snips-dialogue 1.1.2 (0.62.3)'
github ansible / molecule / test / unit / model / v2 / test_platforms_section.py View on Github external
@pytest.mark.parametrize(
    '_required_field', ('distribution', 'plan', 'datacenter', 'distribution')
)
def test_platforms_linode_fields_required(_config, _required_field):
    del _config['platforms'][0][_required_field]
    expected_config = {'platforms': [{0: [{_required_field: ['required field']}]}]}
    assert expected_config == schema_v2.validate(_config)
github rushter / selectolax / tests / test_nodes.py View on Github external
@pytest.mark.parametrize("html,expected", [("<div id="my_node"></div>", 'my_node'), ("<div></div>", None)])
def test_get_node_id(html, expected):
    html_parser = HTMLParser(html)
    node = html_parser.css_first('div')
    assert node.id == expected
github trustlines-protocol / contracts / tests / identity / test_gas_costs_identity.py View on Github external
@pytest.mark.gas_costs
def test_deploy_identity(web3, accounts, gas_values_snapshot):
    A, *rest = accounts

    block_number_before = web3.eth.blockNumber

    deploy_identity(web3, A)

    block_number_after = web3.eth.blockNumber

    gas_cost = 0
    for block_number in range(block_number_after, block_number_before, -1):
        gas_cost += web3.eth.getBlock(block_number).gasUsed

    gas_values_snapshot.assert_gas_costs_match("DEPLOY_IDENTITY", gas_cost)
github alphagov / notifications-admin / tests / app / main / views / test_letters.py View on Github external
@pytest.mark.parametrize('permissions, response_code', [
    (['letter'], 200),
    ([], 403)
])
def test_letters_access_restricted(
    platform_admin_client,
    mocker,
    permissions,
    response_code,
    mock_get_service_templates,
    url,
    service_one,
):
    service_one['permissions'] = permissions

    mocker.patch('app.service_api_client.get_service', return_value={"data": service_one})
github falconry / falcon / tests / test_http_custom_method_routing.py View on Github external
@pytest.mark.skipif(cython, reason='Reloading modules on Cython does not work')
@pytest.mark.parametrize('env_str,expected', [
    ('foo', ['FOO']),
    ('FOO', ['FOO']),
    ('FOO,', ['FOO']),
    ('FOO,BAR', ['FOO', 'BAR']),
    ('FOO, BAR', ['FOO', 'BAR']),
    (' foo , BAR ', ['FOO', 'BAR']),
])
def test_environment_override(cleanup_constants, resource_things, env_str, expected):
    # Make sure we don't have anything in there
    for method in expected:
        assert method not in falcon.constants.COMBINED_METHODS

    os.environ['FALCON_CUSTOM_HTTP_METHODS'] = env_str

    # Reload module to pick up environment variable methods
github pytest-dev / pytest / testing / test_nodes.py View on Github external
@pytest.mark.parametrize("baseid, nodeid, expected", (
    ('', '', True),
    ('', 'foo', True),
    ('', 'foo/bar', True),
    ('', 'foo/bar::TestBaz::()', True),
    ('foo', 'food', False),
    ('foo/bar::TestBaz::()', 'foo/bar', False),
    ('foo/bar::TestBaz::()', 'foo/bar::TestBop::()', False),
    ('foo/bar', 'foo/bar::TestBop::()', True),
))
def test_ischildnode(baseid, nodeid, expected):
    result = nodes.ischildnode(baseid, nodeid)
    assert result is expected
github conda / conda-package-handling / tests / test_api.py View on Github external
@pytest.mark.skipif(sys.platform=="win32", reason="windows and symlinks are not great")
def test_create_package_with_uncommon_conditions_captures_all_content(testing_workdir):
    os.makedirs('src/a_folder')
    os.makedirs('src/empty_folder')
    os.makedirs('src/symlink_stuff')
    with open('src/a_folder/text_file', 'w') as f:
        f.write('weee')
    open('src/empty_file', 'w').close()
    os.link('src/a_folder/text_file', 'src/a_folder/hardlink_to_text_file')
    os.symlink('../a_folder', 'src/symlink_stuff/symlink_to_a')
    os.symlink('../empty_file', 'src/symlink_stuff/symlink_to_empty_file')
    os.symlink('../a_folder/text_file', 'src/symlink_stuff/symlink_to_text_file')

    with tarfile.open('pinkie.tar.bz2', 'w:bz2') as tf:
        tf.add('src/empty_folder', 'empty_folder')
        tf.add('src/empty_file', 'empty_file')
        tf.add('src/a_folder', 'a_folder')