././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1591722979.8923588 pytest-xvfb-2.0.0/0000755000175100001640000000000000000000000014606 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/CHANGELOG.rst0000644000175100001640000000234100000000000016627 0ustar00runnerdocker00000000000000pytest-xvfb changelog ===================== v2.0.0 ------ - PyVirtualDisplay 1.3 and newer is now supported, support for older versions was dropped. - Support for Python 2.7, 3.3 and 3.4 is now dropped. - Support for Python 3.6, 3.7 and 3.8 was added (no code changes required). - Xvfb is now not started anymore in the xdist master process. 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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/MANIFEST.in0000644000175100001640000000006300000000000016343 0ustar00runnerdocker00000000000000include CHANGELOG.rst recursive-include tests *.py ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1591722979.8923588 pytest-xvfb-2.0.0/PKG-INFO0000644000175100001640000001200300000000000015677 0ustar00runnerdocker00000000000000Metadata-Version: 1.2 Name: pytest-xvfb Version: 2.0.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 :: 3 :: Only Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.5 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/README.rst0000644000175100001640000000635100000000000016302 0ustar00runnerdocker00000000000000pytest-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 ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1591722979.8883586 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/0000755000175100001640000000000000000000000020655 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/PKG-INFO0000644000175100001640000001200300000000000021746 0ustar00runnerdocker00000000000000Metadata-Version: 1.2 Name: pytest-xvfb Version: 2.0.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 :: 3 :: Only Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License Requires-Python: >=3.5 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/SOURCES.txt0000644000175100001640000000052000000000000022536 0ustar00runnerdocker00000000000000CHANGELOG.rst MANIFEST.in README.rst pytest_xvfb.py setup.py 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.py././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/dependency_links.txt0000644000175100001640000000000100000000000024723 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/entry_points.txt0000644000175100001640000000003700000000000024153 0ustar00runnerdocker00000000000000[pytest11] xvfb = pytest_xvfb ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/requires.txt0000644000175100001640000000004400000000000023253 0ustar00runnerdocker00000000000000pytest>=2.8.1 pyvirtualdisplay>=1.3 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722979.0 pytest-xvfb-2.0.0/pytest_xvfb.egg-info/top_level.txt0000644000175100001640000000001400000000000023402 0ustar00runnerdocker00000000000000pytest_xvfb ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/pytest_xvfb.py0000644000175100001640000000624000000000000017537 0ustar00runnerdocker00000000000000# -*- 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 is_xdist_master(config): return ( config.getoption("dist", "no") != "no" and not os.environ.get("PYTEST_XDIST_WORKER") ) 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, extra_args=self.args) self._virtual_display.start() self.display = self._virtual_display.display assert self._virtual_display.is_alive() def stop(self): if self.display is not None: # starting worked 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): no_xvfb = config.getoption('--no-xvfb') or is_xdist_master(config) if no_xvfb or not xvfb_available(): config.xvfb = None if (sys.platform.startswith('linux') and 'DISPLAY' in os.environ and not 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 ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1591722979.8923588 pytest-xvfb-2.0.0/setup.cfg0000644000175100001640000000004600000000000016427 0ustar00runnerdocker00000000000000[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/setup.py0000644000175100001640000000304400000000000016321 0ustar00runnerdocker00000000000000#!/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='2.0.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>=1.3'], python_requires='>=3.5', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Topic :: Software Development :: Testing', 'Programming Language :: Python', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', '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', ], }, ) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1591722979.8883586 pytest-xvfb-2.0.0/tests/0000755000175100001640000000000000000000000015750 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/tests/conftest.py0000644000175100001640000000003400000000000020144 0ustar00runnerdocker00000000000000pytest_plugins = 'pytester' ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/tests/test_xvfb.py0000644000175100001640000001345500000000000020336 0ustar00runnerdocker00000000000000# -*- 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> *.XStartError: Xvfb program closed. *", ]) 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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1591722969.0 pytest-xvfb-2.0.0/tests/test_xvfb_windows.py0000644000175100001640000000041600000000000022101 0ustar00runnerdocker00000000000000# -*- 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