pytest-xvfb-1.2.0/0000755000175000017510000000000013414614007015114 5ustar florianflorian00000000000000pytest-xvfb-1.2.0/.gitignore0000644000175000017510000000012513052406346017105 0ustar florianflorian00000000000000/.cache /*.egg-info /__pycache__ /.tox /dist /htmlcov /coverage.xml /.coverage *.pyc pytest-xvfb-1.2.0/.travis.yml0000644000175000017510000000064513052406346017235 0ustar florianflorian00000000000000# Config file for automatic testing at travis-ci.org sudo: false language: python python: - "2.7" - "3.3" - "3.4" - "3.5" - "pypy" addons: apt: packages: - xvfb - xauth install: - pip install tox - "TOX_ENV=${TRAVIS_PYTHON_VERSION/[0-9].[0-9]/py${TRAVIS_PYTHON_VERSION/.}}" script: tox -e $TOX_ENV before_cache: - rm -rf $HOME/.cache/pip/log cache: directories: - $HOME/.cache/pip pytest-xvfb-1.2.0/CHANGELOG.rst0000644000175000017510000000166313414471515017150 0ustar florianflorian00000000000000pytest-xvfb changelog ===================== v1.2.0 ------ - ``Item.get_closest_marker`` is now used, which restores compatibility with pytest 4.1.0 and requires pytest 3.6.0 or newer. v1.1.0 ------ - The ``xvfb_args`` option is now a single line parsed with ``shlex.split``. - The ``XvfbExitedError`` exception now includes stdout and stderr. v1.0.0 ------ - Use `PyVirtualDisplay`_ to start/stop Xvfb - Show a warning on Linux if Xvfb is unavailable .. _PyVirtualDisplay: https://pypi.python.org/pypi/PyVirtualDisplay v0.3.0 ------ - Add a new ``xvfb_xauth`` setting which creates an ``XAUTHORITY`` file. v0.2.1 ------ - The temporary directory searched for logfiles is now hardcoded to /tmp as that's what X11 does as well. v0.2.0 ------ - The ``no_xvfb``-marker is now registered automatically so pytest doesn't fail when run with ``--strict``. - The ``xvfb`` fixture is now session-scoped. v0.1.0 ------ - Initial release pytest-xvfb-1.2.0/LICENSE0000644000175000017510000000207113052406346016124 0ustar florianflorian00000000000000The MIT License (MIT) Copyright (c) 2016 Florian Bruhin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pytest-xvfb-1.2.0/MANIFEST.in0000644000175000017510000000006313236534434016660 0ustar florianflorian00000000000000include CHANGELOG.rst recursive-include tests *.py pytest-xvfb-1.2.0/PKG-INFO0000644000175000017510000001174413414614007016220 0ustar florianflorian00000000000000Metadata-Version: 1.2 Name: pytest-xvfb Version: 1.2.0 Summary: A pytest plugin to run Xvfb for tests. Home-page: https://github.com/The-Compiler/pytest-xvfb Author: Florian Bruhin Author-email: me@the-compiler.org Maintainer: Florian Bruhin Maintainer-email: me@the-compiler.org License: MIT Description: pytest-xvfb =================================== .. image:: https://travis-ci.org/The-Compiler/pytest-xvfb.svg?branch=master :target: https://travis-ci.org/The-Compiler/pytest-xvfb :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/The-Compiler/pytest-xvfb?branch=master :target: https://ci.appveyor.com/project/The-Compiler/pytest-xvfb/branch/master :alt: See Build Status on AppVeyor A pytest plugin to run Xvfb for tests. ---- Installation ------------ You can install "`pytest-xvfb`_" via `pip`_ from `PyPI`_:: $ pip install pytest-xvfb Usage ----- With Xvfb and the plugin installed, your testsuite automatically runs with `Xvfb`_. This allows tests to be run without windows popping up during GUI tests or on systems without a display (like a CI). If Xvfb is not installed, the plugin does not run and your tests will still work as normal. However, a warning message will print to standard output letting you know that Xvfb is not installed. If you're currently using ``xvfb-run`` in something like ``.travis.yml``, simply remove it and install this plugin instead - then you'll also have the benefits of Xvfb locally. Features -------- You can pass ``--no-xvfb`` to explicitly turn off Xvfb (e.g. to visually inspect a failure). You can mark tests with ``@pytest.mark.no_xvfb`` to skip them when they're running with Xvfb. A ``xvfb`` fixture is available with the following attributes: - ``width``: The configured width of the screen. - ``height``: The configured height of the screen. - ``colordepth``: The configured colordepth of the screen. - ``args``: The arguments to be passed to Xvfb. - ``display``: The display number (as int) which is used. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `MIT`_ license, "pytest-xvfb" is free and open source software Thanks ------ This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Thanks to `@cgoldberg`_ for `xvfbwrapper`_ which was the inspiration for this project. Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`pytest-xvfb`: https://pypi.python.org/pypi/pytest-xvfb/ .. _`Xvfb`: http://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`@cgoldberg`: https://github.com/cgoldberg .. _`xvfbwrapper`: https://github.com/cgoldberg/xvfbwrapper .. _`MIT`: http://opensource.org/licenses/MIT .. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause .. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt .. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0 .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/The-Compiler/pytest-xvfb/issues .. _`pytest`: https://github.com/pytest-dev/pytest .. _`tox`: https://tox.readthedocs.org/en/latest/ .. _`pip`: https://pypi.python.org/pypi/pip/ .. _`PyPI`: https://pypi.python.org/pypi Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License pytest-xvfb-1.2.0/README.rst0000644000175000017510000000635113052406346016613 0ustar florianflorian00000000000000pytest-xvfb =================================== .. image:: https://travis-ci.org/The-Compiler/pytest-xvfb.svg?branch=master :target: https://travis-ci.org/The-Compiler/pytest-xvfb :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/The-Compiler/pytest-xvfb?branch=master :target: https://ci.appveyor.com/project/The-Compiler/pytest-xvfb/branch/master :alt: See Build Status on AppVeyor A pytest plugin to run Xvfb for tests. ---- Installation ------------ You can install "`pytest-xvfb`_" via `pip`_ from `PyPI`_:: $ pip install pytest-xvfb Usage ----- With Xvfb and the plugin installed, your testsuite automatically runs with `Xvfb`_. This allows tests to be run without windows popping up during GUI tests or on systems without a display (like a CI). If Xvfb is not installed, the plugin does not run and your tests will still work as normal. However, a warning message will print to standard output letting you know that Xvfb is not installed. If you're currently using ``xvfb-run`` in something like ``.travis.yml``, simply remove it and install this plugin instead - then you'll also have the benefits of Xvfb locally. Features -------- You can pass ``--no-xvfb`` to explicitly turn off Xvfb (e.g. to visually inspect a failure). You can mark tests with ``@pytest.mark.no_xvfb`` to skip them when they're running with Xvfb. A ``xvfb`` fixture is available with the following attributes: - ``width``: The configured width of the screen. - ``height``: The configured height of the screen. - ``colordepth``: The configured colordepth of the screen. - ``args``: The arguments to be passed to Xvfb. - ``display``: The display number (as int) which is used. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `MIT`_ license, "pytest-xvfb" is free and open source software Thanks ------ This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Thanks to `@cgoldberg`_ for `xvfbwrapper`_ which was the inspiration for this project. Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`pytest-xvfb`: https://pypi.python.org/pypi/pytest-xvfb/ .. _`Xvfb`: http://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`@cgoldberg`: https://github.com/cgoldberg .. _`xvfbwrapper`: https://github.com/cgoldberg/xvfbwrapper .. _`MIT`: http://opensource.org/licenses/MIT .. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause .. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt .. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0 .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/The-Compiler/pytest-xvfb/issues .. _`pytest`: https://github.com/pytest-dev/pytest .. _`tox`: https://tox.readthedocs.org/en/latest/ .. _`pip`: https://pypi.python.org/pypi/pip/ .. _`PyPI`: https://pypi.python.org/pypi pytest-xvfb-1.2.0/appveyor.yml0000644000175000017510000000162313052406346017511 0ustar florianflorian00000000000000# What Python version is installed where: # http://www.appveyor.com/docs/installed-software#python environment: matrix: - PYTHON: "C:\\Python27" TOX_ENV: "py27" - PYTHON: "C:\\Python33" TOX_ENV: "py33" - PYTHON: "C:\\Python34" TOX_ENV: "py34" - PYTHON: "C:\\Python35" TOX_ENV: "py35" init: - "%PYTHON%/python -V" - "%PYTHON%/python -c \"import struct;print( 8 * struct.calcsize(\'P\'))\"" install: - "%PYTHON%/Scripts/easy_install -U pip" - "%PYTHON%/Scripts/pip install tox" - "%PYTHON%/Scripts/pip install wheel" build: false # Not a C# project, build stuff at the test step instead. test_script: - "%PYTHON%/Scripts/tox -e %TOX_ENV% -- tests/test_xvfb_windows.py" after_test: - "%PYTHON%/python setup.py bdist_wheel" - ps: "ls dist" artifacts: - path: dist\* #on_success: # - TODO: upload the content of dist/*.whl to a public wheelhouse pytest-xvfb-1.2.0/pytest.ini0000644000175000017510000000005213052406346017145 0ustar florianflorian00000000000000[pytest] addopts = --runpytest=subprocess pytest-xvfb-1.2.0/pytest_xvfb.egg-info/0000755000175000017510000000000013414614007021163 5ustar florianflorian00000000000000pytest-xvfb-1.2.0/pytest_xvfb.egg-info/PKG-INFO0000644000175000017510000001174413414614006022266 0ustar florianflorian00000000000000Metadata-Version: 1.2 Name: pytest-xvfb Version: 1.2.0 Summary: A pytest plugin to run Xvfb for tests. Home-page: https://github.com/The-Compiler/pytest-xvfb Author: Florian Bruhin Author-email: me@the-compiler.org Maintainer: Florian Bruhin Maintainer-email: me@the-compiler.org License: MIT Description: pytest-xvfb =================================== .. image:: https://travis-ci.org/The-Compiler/pytest-xvfb.svg?branch=master :target: https://travis-ci.org/The-Compiler/pytest-xvfb :alt: See Build Status on Travis CI .. image:: https://ci.appveyor.com/api/projects/status/github/The-Compiler/pytest-xvfb?branch=master :target: https://ci.appveyor.com/project/The-Compiler/pytest-xvfb/branch/master :alt: See Build Status on AppVeyor A pytest plugin to run Xvfb for tests. ---- Installation ------------ You can install "`pytest-xvfb`_" via `pip`_ from `PyPI`_:: $ pip install pytest-xvfb Usage ----- With Xvfb and the plugin installed, your testsuite automatically runs with `Xvfb`_. This allows tests to be run without windows popping up during GUI tests or on systems without a display (like a CI). If Xvfb is not installed, the plugin does not run and your tests will still work as normal. However, a warning message will print to standard output letting you know that Xvfb is not installed. If you're currently using ``xvfb-run`` in something like ``.travis.yml``, simply remove it and install this plugin instead - then you'll also have the benefits of Xvfb locally. Features -------- You can pass ``--no-xvfb`` to explicitly turn off Xvfb (e.g. to visually inspect a failure). You can mark tests with ``@pytest.mark.no_xvfb`` to skip them when they're running with Xvfb. A ``xvfb`` fixture is available with the following attributes: - ``width``: The configured width of the screen. - ``height``: The configured height of the screen. - ``colordepth``: The configured colordepth of the screen. - ``args``: The arguments to be passed to Xvfb. - ``display``: The display number (as int) which is used. Contributing ------------ Contributions are very welcome. Tests can be run with `tox`_, please ensure the coverage at least stays the same before you submit a pull request. License ------- Distributed under the terms of the `MIT`_ license, "pytest-xvfb" is free and open source software Thanks ------ This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template. Thanks to `@cgoldberg`_ for `xvfbwrapper`_ which was the inspiration for this project. Issues ------ If you encounter any problems, please `file an issue`_ along with a detailed description. .. _`pytest-xvfb`: https://pypi.python.org/pypi/pytest-xvfb/ .. _`Xvfb`: http://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml .. _`Cookiecutter`: https://github.com/audreyr/cookiecutter .. _`@hackebrot`: https://github.com/hackebrot .. _`@cgoldberg`: https://github.com/cgoldberg .. _`xvfbwrapper`: https://github.com/cgoldberg/xvfbwrapper .. _`MIT`: http://opensource.org/licenses/MIT .. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause .. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt .. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0 .. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _`file an issue`: https://github.com/The-Compiler/pytest-xvfb/issues .. _`pytest`: https://github.com/pytest-dev/pytest .. _`tox`: https://tox.readthedocs.org/en/latest/ .. _`pip`: https://pypi.python.org/pypi/pip/ .. _`PyPI`: https://pypi.python.org/pypi Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Testing Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License pytest-xvfb-1.2.0/pytest_xvfb.egg-info/SOURCES.txt0000644000175000017510000000061713414614006023052 0ustar florianflorian00000000000000.gitignore .travis.yml CHANGELOG.rst LICENSE MANIFEST.in README.rst appveyor.yml pytest.ini pytest_xvfb.py setup.py tox.ini pytest_xvfb.egg-info/PKG-INFO pytest_xvfb.egg-info/SOURCES.txt pytest_xvfb.egg-info/dependency_links.txt pytest_xvfb.egg-info/entry_points.txt pytest_xvfb.egg-info/requires.txt pytest_xvfb.egg-info/top_level.txt tests/conftest.py tests/test_xvfb.py tests/test_xvfb_windows.pypytest-xvfb-1.2.0/pytest_xvfb.egg-info/dependency_links.txt0000644000175000017510000000000113414614006025230 0ustar florianflorian00000000000000 pytest-xvfb-1.2.0/pytest_xvfb.egg-info/entry_points.txt0000644000175000017510000000003713414614006024460 0ustar florianflorian00000000000000[pytest11] xvfb = pytest_xvfb pytest-xvfb-1.2.0/pytest_xvfb.egg-info/requires.txt0000644000175000017510000000004613414614006023562 0ustar florianflorian00000000000000pytest>=2.8.1 pyvirtualdisplay>=0.2.1 pytest-xvfb-1.2.0/pytest_xvfb.egg-info/top_level.txt0000644000175000017510000000001413414614006023707 0ustar florianflorian00000000000000pytest_xvfb pytest-xvfb-1.2.0/pytest_xvfb.py0000644000175000017510000000662113414427347020061 0ustar florianflorian00000000000000# -*- coding: utf-8 -*- import os import re import time import os.path import fnmatch import hashlib import tempfile import subprocess import sys import pyvirtualdisplay import pytest def xvfb_available(): # http://stackoverflow.com/a/28909933/2085149 return any( os.access(os.path.join(path, 'Xvfb'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep) ) class XvfbExitedError(Exception): pass class Xvfb(object): def __init__(self, config): self.width = int(config.getini('xvfb_width')) self.height = int(config.getini('xvfb_height')) self.colordepth = int(config.getini('xvfb_colordepth')) self.args = config.getini('xvfb_args') or [] self.xauth = config.getini('xvfb_xauth') self.display = None self._virtual_display = None def start(self): self._virtual_display = pyvirtualdisplay.Display( backend='xvfb', size=(self.width, self.height), color_depth=self.colordepth, use_xauth=self.xauth) self._virtual_display.cmd.extend(self.args) self._virtual_display.start() self.display = self._virtual_display.display if not self._virtual_display.is_alive(): ret = self._virtual_display.return_code self._virtual_display.wait() # collect outputs stdout = self._virtual_display.stdout stderr = self._virtual_display.stderr raise XvfbExitedError("Xvfb exited with exit code {0}\nXvfb stdout:\n {1}\nXvfb stderr:\n {2}".format( ret, '\n '.join(stdout.splitlines()), '\n '.join(stderr.splitlines()))) def stop(self): self._virtual_display.stop() def pytest_addoption(parser): group = parser.getgroup('xvfb') group.addoption( '--no-xvfb', action='store_true', help='Disable Xvfb for tests.' ) parser.addini('xvfb_width', 'Width of the Xvfb display', default='800') parser.addini('xvfb_height', 'Height of the Xvfb display', default='600') parser.addini('xvfb_colordepth', 'Color depth of the Xvfb display', default='16') parser.addini('xvfb_args', 'Additional arguments for Xvfb', type='args') parser.addini('xvfb_xauth', 'Generate an Xauthority token for Xvfb. Needs xauth.', default=False, type='bool') def pytest_configure(config): if config.getoption('--no-xvfb') or not xvfb_available(): config.xvfb = None if (sys.platform.startswith('linux') and 'DISPLAY' in os.environ and not config.getoption('--no-xvfb')): print('pytest-xvfb could not find Xvfb. ' 'You can install it to prevent windows from being shown.') else: config.xvfb = Xvfb(config) config.xvfb.start() config.addinivalue_line("markers", "no_xvfb: Skip test when using Xvfb") def pytest_unconfigure(config): if getattr(config, 'xvfb', None) is not None: config.xvfb.stop() def pytest_collection_modifyitems(items): for item in items: if item.get_closest_marker('no_xvfb') and item.config.xvfb is not None: skipif_marker = pytest.mark.skipif( True, reason="Skipped with Xvfb") item.add_marker(skipif_marker) @pytest.fixture(scope='session') def xvfb(pytestconfig): return pytestconfig.xvfb pytest-xvfb-1.2.0/setup.cfg0000644000175000017510000000004613414614007016735 0ustar florianflorian00000000000000[egg_info] tag_build = tag_date = 0 pytest-xvfb-1.2.0/setup.py0000644000175000017510000000300113414471564016631 0ustar florianflorian00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import os import codecs from setuptools import setup def read(fname): file_path = os.path.join(os.path.dirname(__file__), fname) return codecs.open(file_path, encoding='utf-8').read() setup( name='pytest-xvfb', version='1.2.0', author='Florian Bruhin', author_email='me@the-compiler.org', maintainer='Florian Bruhin', maintainer_email='me@the-compiler.org', license='MIT', url='https://github.com/The-Compiler/pytest-xvfb', description='A pytest plugin to run Xvfb for tests.', long_description=read('README.rst'), py_modules=['pytest_xvfb'], install_requires=['pytest>=2.8.1', 'pyvirtualdisplay>=0.2.1'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Topic :: Software Development :: Testing', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Operating System :: OS Independent', 'License :: OSI Approved :: MIT License', ], entry_points={ 'pytest11': [ 'xvfb = pytest_xvfb', ], }, ) pytest-xvfb-1.2.0/tests/0000755000175000017510000000000013414614007016256 5ustar florianflorian00000000000000pytest-xvfb-1.2.0/tests/conftest.py0000644000175000017510000000003413052406346020455 0ustar florianflorian00000000000000pytest_plugins = 'pytester' pytest-xvfb-1.2.0/tests/test_xvfb.py0000644000175000017510000001367413211214133020636 0ustar florianflorian00000000000000# -*- coding: utf-8 -*- import os import pytest import pytest_xvfb xauth_available = any( os.access(os.path.join(path, 'xauth'), os.X_OK) for path in os.environ.get('PATH', '').split(os.pathsep) ) @pytest.fixture(autouse=True, scope='session') def ensure_xvfb(): if not pytest_xvfb.xvfb_available(): raise Exception("Tests need Xvfb to run.") def test_xvfb_available(testdir, monkeypatch): monkeypatch.delenv('DISPLAY') testdir.makepyfile(""" import os def test_display(): assert 'DISPLAY' in os.environ """) result = testdir.runpytest() assert result.ret == 0 def test_empty_display(testdir, monkeypatch): monkeypatch.setenv('DISPLAY', '') testdir.makepyfile(""" import os def test_display(): assert 'DISPLAY' in os.environ """) result = testdir.runpytest() assert os.environ['DISPLAY'] == '' assert result.ret == 0 def test_xvfb_unavailable(testdir, monkeypatch): monkeypatch.setenv('PATH', '') monkeypatch.setenv('DISPLAY', ':42') testdir.makepyfile(""" import os def test_display(): assert os.environ['DISPLAY'] == ':42' """) assert os.environ['DISPLAY'] == ':42' result = testdir.runpytest() result.stdout.fnmatch_lines('* could not find Xvfb.*') assert result.ret == 0 def test_no_xvfb_arg(testdir, monkeypatch): monkeypatch.setenv('DISPLAY', ':42') testdir.makepyfile(""" import os def test_display(): assert os.environ['DISPLAY'] == ':42' """) assert os.environ['DISPLAY'] == ':42' result = testdir.runpytest('--no-xvfb') assert result.ret == 0 @pytest.mark.parametrize('configured', [True, False]) def test_screen_size(testdir, configured): try: import tkinter except ImportError: pytest.importorskip('Tkinter') if configured: testdir.makeini(""" [pytest] xvfb_width = 1024 xvfb_height = 768 xvfb_colordepth = 8 """) expected_width = 1024 expected_height = 768 expected_depth = 8 else: expected_width = 800 expected_height = 600 expected_depth = 16 testdir.makepyfile(""" try: import tkinter as tk except ImportError: import Tkinter as tk def test_screen_size(): root = tk.Tk() assert root.winfo_screenwidth() == {width} assert root.winfo_screenheight() == {height} assert root.winfo_screendepth() == {depth} """.format(width=expected_width, height=expected_height, depth=expected_depth)) result = testdir.runpytest() assert result.ret == 0 def test_failing_start(testdir, monkeypatch): testdir.makeini(""" [pytest] xvfb_args = -foo """) testdir.makepyfile(""" def test_none(): pass """) result = testdir.runpytest() result.stderr.fnmatch_lines([ "INTERNALERROR> *XvfbExitedError: Xvfb exited with exit code 1", "INTERNALERROR> Xvfb stdout:", "INTERNALERROR> Xvfb stderr:", "INTERNALERROR> Unrecognized option: -foo", ]) assert 'OSError' not in str(result.stderr) @pytest.mark.parametrize('args, outcome', [ ([], '1 passed, 1 skipped'), (['--no-xvfb'], '2 passed'), ]) def test_no_xvfb_marker(testdir, args, outcome): testdir.makepyfile(""" import pytest @pytest.mark.no_xvfb def test_marked(): pass def test_unmarked(): pass """) res = testdir.runpytest(*args) res.stdout.fnmatch_lines('*= {0}*'.format(outcome)) def test_xvfb_fixture(testdir): testdir.makepyfile(""" import os def test_display(xvfb): assert ':{}'.format(xvfb.display) == os.environ['DISPLAY'] def test_screen(xvfb): assert xvfb.width == 800 assert xvfb.height == 600 assert xvfb.colordepth == 16 def test_args(xvfb): assert xvfb.args == [] """) result = testdir.runpytest() assert result.ret == 0 def test_early_display(monkeypatch, testdir): """Make sure DISPLAY is set in a session-scoped fixture already.""" monkeypatch.delenv('DISPLAY') testdir.makepyfile(""" import os import pytest @pytest.yield_fixture(scope='session', autouse=True) def fixt(): assert 'DISPLAY' in os.environ yield def test_foo(): pass """) def test_strict_markers(testdir): testdir.makepyfile(""" import pytest @pytest.mark.no_xvfb def test_marked(): pass """) result = testdir.runpytest('--strict') assert result.ret == 0 def test_xvfb_session_fixture(testdir): """Make sure the xvfb fixture can be used from a session-wide one.""" testdir.makepyfile(""" import pytest @pytest.fixture(scope='session') def fixt(xvfb): pass def test_fixt(fixt): pass """) result = testdir.runpytest() assert result.ret == 0 @pytest.mark.skipif(not xauth_available, reason='no xauth') def test_xvfb_with_xauth(testdir): original_auth = os.environ.get('XAUTHORITY') testdir.makeini(""" [pytest] xvfb_xauth = True """) testdir.makepyfile(""" import os def test_xauth(): print('\\nXAUTHORITY: ' + os.environ['XAUTHORITY']) assert os.path.isfile(os.environ['XAUTHORITY']) assert os.access(os.environ['XAUTHORITY'], os.R_OK) """) result = testdir.runpytest('-s') # Get and parse the XAUTHORITY: line authline = next(l for l in result.outlines if l.startswith('XAUTHORITY:')) authfile = authline.split(' ', 1)[1] assert result.ret == 0 # Make sure the authfile is deleted assert not os.path.exists(authfile) assert os.environ.get('XAUTHORITY') == original_auth pytest-xvfb-1.2.0/tests/test_xvfb_windows.py0000644000175000017510000000041613052406346022412 0ustar florianflorian00000000000000# -*- coding: utf-8 -*- """Make sure things don't break on Windows with no Xvfb available.""" def test_xvfb_windows(testdir): testdir.makepyfile(""" def test_nothing(): pass """) result = testdir.runpytest() assert result.ret == 0 pytest-xvfb-1.2.0/tox.ini0000644000175000017510000000031513052406346016431 0ustar florianflorian00000000000000# For more information about tox, see https://tox.readthedocs.org/en/latest/ [tox] envlist = py27,py33,py34,py35,pypy [testenv] deps = pytest pyvirtualdisplay commands = py.test {posargs:tests}