
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
pytest-services
Advanced tools
.. image:: https://img.shields.io/pypi/v/pytest-services.svg :target: https://pypi.python.org/pypi/pytest-services .. image:: https://img.shields.io/pypi/pyversions/pytest-services.svg :target: https://pypi.python.org/pypi/pytest-services .. image:: https://img.shields.io/coveralls/pytest-dev/pytest-services/master.svg :target: https://coveralls.io/r/pytest-dev/pytest-services .. image:: https://travis-ci.org/pytest-dev/pytest-services.svg?branch=master :target: https://travis-ci.org/pytest-dev/pytest-services .. image:: https://readthedocs.org/projects/pytest-services/badge/?version=latest :target: https://readthedocs.org/projects/pytest-services/?badge=latest :alt: Documentation Status
::
pip install pytest-services
.. _pytest: http://pytest.org .. _pytest-xdist: https://pypi.python.org/pypi/pytest-xdist .. _pytest-splinter: https://pypi.python.org/pypi/pytest-splinter .. _pytest-bdd: https://pypi.python.org/pypi/pytest-bdd .. _pytest-django: https://pypi.python.org/pypi/pytest-django .. _memcached: http://memcached.org .. _xvfb: http://en.wikipedia.org/wiki/Xvfb .. _mysql-server: http://dev.mysql.com/
The plugin provides a set of fixtures and utility functions to start service processes for your tests with pytest_
--run-services command line argument (see below).Infrastructure fixtures
local if tests are not run using
pytest-xdist_ (with --dist command line option set to load).
Has a deprecated alias slave_id which will be removed in a future version... code-block:: python
@pytest.fixture(scope='session')
def memcached(request, run_services, memcached_socket, watcher_getter):
"""The memcached instance which is ready to be used by the tests."""
if run_services:
return watcher_getter(
name='memcached',
arguments=['-s', memcached_socket],
checker=lambda: os.path.exists(memcached_socket),
# Needed for the correct execution order of finalizers
request=request,
)
/tmp by default.root_dir.
Automatically removed recursively at the end of the test session.Temporary directory (disk based), subfolder of the base_dir.
Used for strictly temporary artifacts (for example - folder where files are uploaded from the user input)./var/shm by default, with a fallback to 'root_dir`. Note that if apparmor is running on your system, most
likely it will prevent your test service to use it (for example - mysql has it's apparmor profile). You you'll need
to disable such profile in apparmor configuration.
Example of disabling apparmor for mysqld:.. code-block:: sh
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo /etc/init.d/apparmor restart
memory_root_dir.
Automatically removed recursively at the end of the test session.Temporary directory (memory based), subfolder of the base_dir.memory_root_dir./var/run but local for test session). Subfolder of
memory_root_dir.Service fixtures
pylibmc installed or memcache indicated as an extra (pip install 'pytest-services[memcached]').run_services fixture by default.
Requires pylibmc installed or memcache indicated as an extra (pip install 'pytest-services[memcached]').pylibmc installed or memcache indicated as an extra (pip install 'pytest-services[memcached]').system database.mysql_database fixture which is used by mysql one.(1366, 768, 8).Utility functions
Django settings ^^^^^^^^^^^^^^^
In some cases, there's a need of switching django settings during test run, because several django projects are tested
whithin the single test suite.
pytest_services.django_settings simplifies switching of django settings to a single function call:
Example of usage:
conftest.py:
.. code-block:: python
from pytest_services import django_settings
django_settings.clean_django_settings()
django_settings.setup_django_settings('your.project.settings')
Note that the nice project pytest-django_ doesn't help with the situation, as it's single django project oriented, as well as standard django testing technique. Single project approach works fine, as long as there are no fixtures to share between them, but when there are fixtures to share, then you can get benefit of joining several django projects tests into a single test run, because all session-scoped fixtures will be instantiated only once for all projects tests. The benefit is only visible if you have big enough test suite and your fixtures are heavy enough.
--run-services
Force services to be run even if tests are executed in a non-distributed way (without pytest-xdist_).--xvfb-display
Skip xvfb service to run and use provided display. Useful when you need to run all services except the xvfb_
to debug your browser tests, if, for example you use pytest-splinter_ with or without pytest-bdd_.test_your_test.py:
.. code-block:: python
import MySQLdb
def test_some_mysql_stuff(mysql):
"""Test using mysql server."""
conn = MySQLdb.connect(user='root')
If you have questions, bug reports, suggestions, etc. please create an issue on
the GitHub project page <https://github.com/pytest-dev/pytest-services>_.
This software is licensed under the MIT license <http://en.wikipedia.org/wiki/MIT_License>_
See License file <https://github.com/pytest-dev/pytest-services/blob/master/LICENSE.txt>_
© 2014 Anatoly Bubenkov, Paylogic International and others.
Anatoly Bubenkov <bubenkoff@gmail.com>_
idea and implementation
These people have contributed to pytest-services, in alphabetical order:
Alessio Bogon <youtux@github.com>_Dmitrijs Milajevs <dimazest@gmail.com>_Jason R. Coombs <jaraco@jaraco.com>_Joep van Dijken <joepvandijken@github.com>_Magnus Staberg <magnus@staberg.io>_Michael Shriver <mshriver@redhat.com>_Oleg Pidsadnyi <oleg.pidsadnyi@gmail.com>_Zac Hatfield-Dodds <zac@zhd.dev>_distutils.spawn.find_executable with shutil.which. The package distutils is deprecated.zc.lockfile.LockError in file_lock, use existing timeout kwarg (mshriver)slave_id fixture in favor of worker_id,
for compatibility with pytest-xdist 2.zc.lockfile for lockfile behavior.mysql --initialize support.mysql_defaults_file
fixture would prevent startup of mysql.pytest_services.locks.lock_file.request param to watcher_getter to have proper execution order
of finalizers (youtux).FAQs
Services plugin for pytest testing framework
We found that pytest-services demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.