Here are the examples of the python api pytest.mark.usefixtures taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
176 Examples
3
Example 1
@pytest.mark.usefixtures('qapp')
def test_default_config(self):
"""Test validating of the default config."""
conf = config.ConfigManager()
conf.read(None, None)
conf._validate_all()
3
Example 2
Project: plumbum Source File: test_remote.py
@pytest.mark.usefixtures("testdir")
def test_download_upload(self):
with self._connect() as rem:
rem.upload("test_remote.py", "/tmp")
r_ls = rem["ls"]
r_rm = rem["rm"]
assert "test_remote.py" in r_ls("/tmp").splitlines()
rem.download("/tmp/test_remote.py", "/tmp/test_download.txt")
r_rm("/tmp/test_remote.py")
r_rm("/tmp/test_download.txt")
3
Example 3
Project: smartsheet-python-sdk Source File: test_sheets.py
@pytest.mark.usefixtures('tmpdir')
def test_get_sheet_as_excel(self, smart_setup, tmpdir):
smart = smart_setup['smart']
action = smart.Sheets.get_sheet_as_excel(
smart_setup['sheet'].id,
tmpdir.strpath
)
assert action.message == 'SUCCESS'
3
Example 4
Project: DockCI Source File: test_util_db.py
@pytest.mark.usefixtures('db')
def test_api_as_admin(self, client, user, admin_user):
response = client.get(
'/api/v1/_test/require_me_or_admin/%s' % user.id,
headers={
'x_dockci_username': admin_user.email,
'x_dockci_password': 'testpass',
},
)
assert response.status_code == 999
3
Example 5
Project: DockCI Source File: test_jwt_api_db.py
@pytest.mark.usefixtures('db')
def test_unknown_role(self, client, admin_user):
""" Test creating a service token with the agent internal role """
response = client.post('/api/v1/jwt/service', headers={
'x_dockci_username': admin_user.email,
'x_dockci_password': 'testpass',
}, data={
'name': 'test',
'roles': ['faketest'],
})
assert response.status_code == 400
response_data = json.loads(response.data.decode())
assert response_data == {
'message': {'roles': 'Roles not found: faketest'}
}
3
Example 6
Project: qtile Source File: test_hook.py
@pytest.mark.usefixtures("hook_fixture")
def test_can_unsubscribe_from_hook():
test = Call(0)
libqtile.manager.hook.subscribe.group_window_add(test)
libqtile.manager.hook.fire("group_window_add", 3)
assert test.val == 3
libqtile.manager.hook.unsubscribe.group_window_add(test)
libqtile.manager.hook.fire("group_window_add", 4)
assert test.val == 3
3
Example 7
Project: qutebrowser Source File: test_utils.py
@pytest.mark.usefixtures('freezer')
def test_resource_filename():
"""Read a test file."""
filename = utils.resource_filename(os.path.join('utils', 'testfile'))
with open(filename, 'r', encoding='utf-8') as f:
assert f.read().splitlines()[0] == "Hello World!"
3
Example 8
Project: pycontw2016 Source File: test_render_row.py
@pytest.mark.usefixtures('simple_renderer')
def test_render_partial_belt_events_row(
parser, utils,
partial_belt_begin_time, partial_belt_end_time, partial_belt_events):
times = [partial_belt_begin_time, partial_belt_end_time]
rendered = renderers.render_row(times, partial_belt_events)
assert utils.is_safe(rendered)
assert parser.arrange(rendered) == parser.arrange("""
|1:00 2:00|
<div class="time-table__slot">
<div class="row">
|1:00 2:00|
|Refreshment|
</div>
</div>
""")
3
Example 9
Project: rest_toolkit Source File: test_sql.py
@pytest.mark.usefixtures('sql_session')
def test_update_instance():
balloon = BalloonModel(figure=u'Giraffe')
Session.add(balloon)
Session.flush()
request = DummyRequest(matchdict={'id': balloon.id})
resource = BalloonResource(request)
resource.update_from_dict({'figure': u'Elephant'})
assert balloon.figure == u'Elephant'
3
Example 10
Project: pycontw2016 Source File: test_render_row.py
@pytest.mark.usefixtures('simple_renderer')
def test_render_partial_block_events_row(
parser, utils, partial_block_begin_time,
partial_block_end_time, partial_block_events):
times = [partial_block_begin_time, partial_block_end_time]
rendered = renderers.render_row(times, partial_block_events)
assert utils.is_safe(rendered)
assert parser.arrange(rendered) == parser.arrange("""
|5:00 6:00|
<div class="time-table__slot">
<div class="row">
|5:00 6:00|
|Boost Maintainability|
|We Made the PyCon TW 2016 Website|
|Deep Learning and Application in Python|
</div>
</div>
""")
3
Example 11
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_admin_update_roles(self, client, admin_user, role):
""" Admin user updates roles """
response = client.post('/api/v1/me', headers={
'x_dockci_username': admin_user.email,
'x_dockci_password': 'testpass',
}, data={
'roles': ['admin', role.name],
})
assert response.status_code == 200
DB.session.refresh(admin_user)
assert set(
irole.name for irole in admin_user.roles
) == set(('admin', role.name))
3
Example 12
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_add_multiple(self, role):
""" Add multiple roles to a user with no roles """
user = User()
rest_set_roles(user, ['admin', role.name])
assert [role.name for role in user.roles] == ['admin', role.name]
3
Example 13
Project: qtile Source File: test_hook.py
@pytest.mark.usefixtures("hook_fixture")
def test_hook_calls_subscriber():
test = Call(0)
libqtile.manager.hook.subscribe.group_window_add(test)
libqtile.manager.hook.fire("group_window_add", 8)
assert test.val == 8
3
Example 14
Project: DockCI Source File: test_util_db.py
@pytest.mark.usefixtures('db')
def test_api_as_other(self, client, user, admin_user):
response = client.get(
'/api/v1/_test/require_me_or_admin/%s' % admin_user.id,
headers={
'x_dockci_username': user.email,
'x_dockci_password': 'testpass',
},
)
assert response.status_code == 401
3
Example 15
Project: cookiecutter Source File: test_output_folder.py
@pytest.mark.usefixtures('clean_system', 'remove_output_folder')
def test_exception_when_output_folder_exists():
context = generate.generate_context(
context_file='tests/test-output-folder/cookiecutter.json'
)
output_folder = context['cookiecutter']['test_name']
if not os.path.exists(output_folder):
os.makedirs(output_folder)
with pytest.raises(exceptions.OutputDirExistsException):
generate.generate_files(
context=context,
repo_dir='tests/test-output-folder'
)
3
Example 16
Project: qutebrowser Source File: test_debug.py
@pytest.mark.usefixtures('qapp')
def test_get_all_objects_qapp(self):
objects = debug.get_all_objects()
event_dispatcher = '<PyQt5.QtCore.QAbstractEventDispatcher object at'
session_manager = '<PyQt5.QtGui.QSessionManager object at'
assert event_dispatcher in objects or session_manager in objects
3
Example 17
Project: smartsheet-python-sdk Source File: test_reports.py
@pytest.mark.usefixtures('tmpdir')
def test_get_report_as_excel(self, smart_setup, tmpdir):
smart = smart_setup['smart']
try:
action = smart.Reports.get_report_as_excel(
TestReports.reports[0].id,
tmpdir.strpath
)
assert action.message == 'SUCCESS'
assert isinstance(action, smart.models.DownloadedFile)
except IndexError:
pytest.skip('no reports in test account')
3
Example 18
Project: plumbum Source File: test_local.py
@pytest.mark.usefixtures("testdir")
def test_iterdir(self):
cwd = local.path('.')
files = list(cwd.iterdir())
assert cwd / 'test_local.py' in files
assert cwd / 'test_remote.py' in files
3
Example 19
Project: cookiecutter Source File: test_generate_files.py
@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
def test_return_rendered_project_dir():
os.mkdir('tests/custom_output_dir')
project_dir = generate.generate_files(
context={
'cookiecutter': {'food': 'pizzä'}
},
repo_dir=os.path.abspath('tests/test-generate-files'),
output_dir='tests/custom_output_dir'
)
assert project_dir == os.path.abspath(
'tests/custom_output_dir/inputpizzä/'
)
3
Example 20
Project: rest_toolkit Source File: test_sql.py
@pytest.mark.usefixtures('sql_session')
def test_known_id():
balloon = BalloonModel(figure=u'Giraffe')
Session.add(balloon)
Session.flush()
config = Configurator()
config.include('rest_toolkit')
config.scan('resource_sql')
app = make_app(config)
r = app.get('/balloons/%s' % balloon.id)
assert r.json['figure'] == u'Giraffe'
3
Example 21
Project: YouCompleteMe-x64 Source File: test_cache.py
@pytest.mark.usefixtures("isolated_jedi_cache")
def test_modulepickling_delete_incompatible_cache():
item = ParserCacheItem('fake parser')
path = 'fake path'
cache1 = ParserPicklingCls()
cache1.version = 1
cache1.save_parser(path, item)
cached1 = load_stored_item(cache1, path, item)
assert cached1 == item.parser
cache2 = ParserPicklingCls()
cache2.version = 2
cached2 = load_stored_item(cache2, path, item)
assert cached2 is None
3
Example 22
@pytest.mark.usefixtures('db')
def test_non_admin(self, client, user):
""" Test creating a service token without admin """
response = client.post('/api/v1/jwt/service', headers={
'x_dockci_username': user.email,
'x_dockci_password': 'testpass',
}, data={
'name': 'test',
'roles': ['agent'],
})
assert response.status_code == 401
3
Example 23
Project: cookiecutter Source File: test_get_user_config.py
@pytest.mark.usefixtures('back_up_rc')
def test_get_user_config_valid(user_config_path, custom_config):
"""
Get config from a valid ~/.cookiecutterrc file
"""
shutil.copy('tests/test-config/valid-config.yaml', user_config_path)
conf = config.get_user_config()
assert conf == custom_config
3
Example 24
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_add_to_empty(self):
""" Add a role to a user with no roles """
user = User()
rest_set_roles(user, ['admin'])
assert [role.name for role in user.roles] == ['admin']
3
Example 25
Project: pycontw2016 Source File: test_render_row.py
@pytest.mark.usefixtures('simple_renderer')
def test_render_block_events_row(
parser, utils, block_begin_time, block_end_time, block_events):
times = [block_begin_time, block_end_time]
rendered = renderers.render_row(times, block_events)
assert utils.is_safe(rendered)
assert parser.arrange(rendered) == parser.arrange("""
|7:00 8:00|
<div class="time-table__slot">
<div class="row">
|7:00 8:00|
|Boost Maintainability|
|We Made the PyCon TW 2016 Website|
|Deep Learning and Application in Python|
|Free-market sub-orbital tattoo|
</div>
</div>
""")
3
Example 26
@pytest.mark.usefixtures('db')
def test_me(self, client, admin_user):
""" User accessing me API sees correct data """
response = client.get('/api/v1/me', headers={
'x_dockci_username': admin_user.email,
'x_dockci_password': 'testpass',
})
assert response.status_code == 200
response_data = json.loads(response.data.decode())
response_data.pop('avatar') # gravatar is too hard
assert response_data == dict(
id=admin_user.id,
confirmed_at=None,
active=True,
email=admin_user.email,
emails=[admin_user.email],
roles=[{'name': 'admin', 'description': 'Administrators'}],
)
3
Example 27
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_set_with_existing(self, role, user):
""" Set roles on a user with an existing role """
user.roles.append(role)
DB.session.add(role)
DB.session.add(user)
DB.session.commit()
rest_set_roles(user, [role.name])
assert [role.name for role in user.roles] == [role.name]
3
Example 28
Project: pytest Source File: test_tmpdir.py
@pytest.mark.usefixtures("break_getuser")
@pytest.mark.skipif(sys.platform.startswith('win'), reason='no os.getuid on windows')
def test_get_user_uid_not_found():
"""Test that get_user() function works even if the current process's
user id does not correspond to a valid user (e.g. running pytest in a
Docker container with 'docker run -u'.
"""
from _pytest.tmpdir import get_user
assert get_user() is None
3
Example 29
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_no_admin_update_roles(self, client, user, role):
""" Non-admin user updates roles """
response = client.post('/api/v1/me', headers={
'x_dockci_username': user.email,
'x_dockci_password': 'testpass',
}, data={
'roles': [role.name],
})
assert response.status_code == 401
DB.session.refresh(user)
assert list(user.roles) == []
DB.session.delete(role)
DB.session.commit()
3
Example 30
Project: cookiecutter Source File: test_get_user_config.py
@pytest.mark.usefixtures('back_up_rc')
def test_get_user_config_nonexistent():
"""
Get config from a nonexistent ~/.cookiecutterrc file
"""
assert config.get_user_config() == config.DEFAULT_CONFIG
3
Example 31
Project: DockCI Source File: test_util_db.py
@pytest.mark.usefixtures('db')
def test_api_as_me(self, client, user, admin_user):
response = client.get(
'/api/v1/_test/require_me_or_admin/%s' % user.id,
headers={
'x_dockci_username': user.email,
'x_dockci_password': 'testpass',
},
)
assert response.status_code == 999
3
Example 32
Project: qtile Source File: test_hook.py
@pytest.mark.usefixtures("hook_fixture")
def test_subscribers_can_be_added_removed():
test = Call(0)
libqtile.manager.hook.subscribe.group_window_add(test)
assert libqtile.manager.hook.subscriptions
libqtile.manager.hook.clear()
assert not libqtile.manager.hook.subscriptions
3
Example 33
Project: qutebrowser Source File: test_qt_javascript.py
@pytest.mark.usefixtures('redirect_webengine_data')
@pytest.mark.parametrize('js_enabled, expected', [(True, 2.0), (False, 2.0)])
def test_simple_js_webengine(callback_checker, webengineview, js_enabled,
expected):
"""With QtWebEngine, runJavaScript works even when JS is off."""
# pylint: disable=no-name-in-module,useless-suppression
# If we get there (because of the webengineview fixture) we can be certain
# QtWebEngine is available
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
webengineview.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
js_enabled)
webengineview.page().runJavaScript('1 + 1', callback_checker.callback)
callback_checker.check(expected)
3
Example 34
Project: cookiecutter Source File: test_generate_context.py
@pytest.mark.usefixtures('clean_system')
@pytest.mark.parametrize('input_params, expected_context', context_data())
def test_generate_context(input_params, expected_context):
"""
Test the generated context for several input parameters against the
according expected context.
"""
assert generate.generate_context(**input_params) == expected_context
3
Example 35
Project: qutebrowser Source File: test_configtypes_hypothesis.py
@pytest.mark.usefixtures('qapp', 'config_tmpdir')
@pytest.mark.parametrize('klass', gen_classes())
@hypothesis.given(strategies.text())
@hypothesis.example('\x00')
def test_configtypes_hypothesis(klass, s):
if (klass in [configtypes.File, configtypes.UserStyleSheet] and
sys.platform == 'linux' and
not os.environ.get('DISPLAY', '')):
pytest.skip("No DISPLAY available")
try:
klass().validate(s)
except configexc.ValidationError:
pass
else:
klass().transform(s)
3
Example 36
Project: smartsheet-python-sdk Source File: test_reports.py
@pytest.mark.usefixtures('tmpdir')
def test_get_report_as_csv(self, smart_setup, tmpdir):
smart = smart_setup['smart']
try:
action = smart.Reports.get_report_as_csv(
TestReports.reports[0].id,
tmpdir.strpath
)
assert action.message == 'SUCCESS'
assert isinstance(action, smart.models.DownloadedFile)
except IndexError:
pytest.skip('no reports in test account')
3
Example 37
Project: qutebrowser Source File: test_standarddir.py
@pytest.mark.usefixtures('reset_standarddir')
@pytest.mark.parametrize('data_subdir, config_subdir, expected', [
('foo', 'foo', 'foo/data'),
('foo', 'bar', 'foo'),
])
def test_get_fake_windows_equal_dir(data_subdir, config_subdir, expected,
monkeypatch, tmpdir):
"""Test _get with a fake Windows OS with equal data/config dirs."""
locations = {
QStandardPaths.DataLocation: str(tmpdir / data_subdir),
QStandardPaths.ConfigLocation: str(tmpdir / config_subdir),
}
monkeypatch.setattr('qutebrowser.utils.standarddir.os.name', 'nt')
monkeypatch.setattr(
'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
locations.get)
expected = str(tmpdir / expected)
assert standarddir.data() == expected
3
Example 38
Project: pycontw2016 Source File: test_render_row.py
@pytest.mark.usefixtures('simple_renderer')
def test_render_belt_events_row(parser, utils, keynote_belt_event):
times = [keynote_belt_event.begin_time, keynote_belt_event.end_time]
rendered = renderers.render_row(times, [keynote_belt_event])
assert utils.is_safe(rendered)
assert parser.arrange(rendered) == parser.arrange("""
|9:00 10:00|
<div class="time-table__slot">
<div class="row">
|9:00 10:00|
|Keynote: Amber Brown|
</div>
</div>
""")
3
Example 39
@pytest.mark.usefixtures('import_fake')
def test_all_present(self):
"""Test with all modules present in version 1.2.3."""
expected = ['sip: yes', 'colorama: 1.2.3', 'pypeg2: 1.2.3',
'jinja2: 1.2.3', 'pygments: 1.2.3', 'yaml: 1.2.3',
'cssutils: 1.2.3', 'typing: yes',
'PyQt5.QtWebEngineWidgets: yes']
assert version._module_versions() == expected
3
Example 40
Project: smartsheet-python-sdk Source File: test_sheets.py
@pytest.mark.usefixtures('tmpdir')
def test_get_sheet_as_pdf(self, smart_setup, tmpdir):
smart = smart_setup['smart']
action = smart.Sheets.get_sheet_as_pdf(
smart_setup['sheet'].id,
tmpdir.strpath
)
assert action.message == 'SUCCESS'
3
Example 41
@pytest.mark.usefixtures("testdir")
def test_slow(self):
delete('nohup.out')
sp = bash['slow_process.bash']
sp & NOHUP
time.sleep(.5)
assert self.read_file('slow_process.out') == 'Starting test\n1\n'
assert self.read_file('nohup.out') == '1\n'
time.sleep(1)
assert self.read_file('slow_process.out') == 'Starting test\n1\n2\n'
assert self.read_file('nohup.out') == '1\n2\n'
time.sleep(2)
delete('nohup.out', 'slow_process.out')
3
Example 42
Project: cookiecutter Source File: test_cli.py
@pytest.mark.usefixtures('remove_fake_project_dir')
def test_cli_extra_context_invalid_format(cli_runner):
result = cli_runner(
'tests/fake-repo-pre/',
'--no-input',
'-v',
'ExtraContextWithNoEqualsSoInvalid',
)
assert result.exit_code == 2
assert 'Error: Invalid value for "extra_context"' in result.output
assert 'should contain items of the form key=value' in result.output
3
Example 43
@pytest.mark.usefixtures('sql_session')
def test_unknown_id():
config = Configurator()
config.include('rest_toolkit')
config.scan('resource_sql')
app = make_app(config)
r = app.get('/balloons/1', status=404)
3
Example 44
Project: smartsheet-python-sdk Source File: test_sheets.py
@pytest.mark.usefixtures('tmpdir')
def test_get_sheet_as_csv(self, smart_setup, tmpdir):
smart = smart_setup['smart']
action = smart.Sheets.get_sheet_as_csv(
smart_setup['sheet'].id,
tmpdir.strpath,
str(smart_setup['sheet'].id) + '.csv'
)
assert action.message == 'SUCCESS'
3
Example 45
Project: pycontw2016 Source File: test_render_row.py
@pytest.mark.usefixtures('simple_renderer')
def test_render_partial_belt_block_events_row(
parser, utils, partial_belt_block_begin_time,
partial_belt_block_end_time, partial_belt_block_events):
times = [partial_belt_block_begin_time, partial_belt_block_end_time]
rendered = renderers.render_row(times, partial_belt_block_events)
assert utils.is_safe(rendered)
assert parser.arrange(rendered) == parser.arrange("""
|3:00 4:00|
<div class="time-table__slot">
<div class="row">
|3:00 4:00|
|Refreshment|
|Free-market sub-orbital tattoo|
</div>
</div>
""")
3
Example 46
Project: cookiecutter Source File: test_cli.py
@pytest.mark.usefixtures('remove_fake_project_dir')
def test_cli_extra_context(cli_runner):
result = cli_runner(
'tests/fake-repo-pre/',
'--no-input',
'-v',
'project_name=Awesomez',
)
assert result.exit_code == 0
assert os.path.isdir('fake-project')
with open(os.path.join('fake-project', 'README.rst')) as f:
assert 'Project name: **Awesomez**' in f.read()
3
Example 47
Project: cookiecutter Source File: test_cookiecutter_invocation.py
@pytest.mark.usefixtures('clean_system')
def test_should_invoke_main(monkeypatch, project_dir):
monkeypatch.setenv('PYTHONPATH', '.')
subprocess.check_call([
sys.executable,
'-m',
'cookiecutter.cli',
'tests/fake-repo-tmpl',
'--no-input'
])
assert os.path.isdir(project_dir)
3
Example 48
Project: cookiecutter Source File: test_get_user_config.py
@pytest.mark.usefixtures('back_up_rc')
def test_get_user_config_invalid(user_config_path):
"""
Get config from an invalid ~/.cookiecutterrc file
"""
shutil.copy('tests/test-config/invalid-config.yaml', user_config_path)
with pytest.raises(InvalidConfiguration):
config.get_user_config()
3
Example 49
Project: pytest Source File: test_tmpdir.py
@pytest.mark.usefixtures("break_getuser")
@pytest.mark.skipif(sys.platform.startswith('win'), reason='no os.getuid on windows')
def test_tmpdir_fallback_uid_not_found(testdir):
"""Test that tmpdir works even if the current process's user id does not
correspond to a valid user.
"""
testdir.makepyfile("""
import pytest
def test_some(tmpdir):
assert tmpdir.isdir()
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
3
Example 50
Project: DockCI Source File: test_user_api_db.py
@pytest.mark.usefixtures('db')
def test_add_fake(self):
""" Add a fake role to a user causes 400 and error message """
user = User()
with pytest.raises(werkzeug.exceptions.BadRequest) as excinfo:
rest_set_roles(user, ['testfake', 'testmore'])
assert 'testfake' in excinfo.value.data['message']['roles']
assert 'testmore' in excinfo.value.data['message']['roles']