mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-03 01:18:00 +03:00
tests: Add pytest conftest.py
Makes 'pytest' and 'pytest --cov' work for the standard tests. uitests run with `pytest --uitests --cov=virtManager`. test_urls.py, test_dist.py, test_inject.py need to be invoked like pytest $PATH Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
4f15e2d6eb
commit
e9b3ed509f
@ -1,4 +1,10 @@
|
|||||||
|
[run]
|
||||||
|
source=virtinst/
|
||||||
|
omit=virtinst/progress.py
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
|
skip_covered = yes
|
||||||
|
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
# Have to re-enable the standard pragma
|
# Have to re-enable the standard pragma
|
||||||
pragma: no cover
|
pragma: no cover
|
||||||
|
2
setup.py
2
setup.py
@ -410,7 +410,7 @@ class TestBaseCommand(distutils.core.Command):
|
|||||||
if self.coverage:
|
if self.coverage:
|
||||||
import coverage
|
import coverage
|
||||||
omit = ["/usr/*", "/*/tests/*", "*progress.py"]
|
omit = ["/usr/*", "/*/tests/*", "*progress.py"]
|
||||||
cov = coverage.coverage(omit=omit)
|
cov = coverage.coverage()
|
||||||
cov.erase()
|
cov.erase()
|
||||||
if not self._external_coverage:
|
if not self._external_coverage:
|
||||||
cov.start()
|
cov.start()
|
||||||
|
55
tests/conftest.py
Normal file
55
tests/conftest.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# This work is licensed under the GNU GPLv2 or later.
|
||||||
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption("--uitests", action="store_true", default=False,
|
||||||
|
help="Run dogtail UI tests")
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_ignore_collect(path, config):
|
||||||
|
uitests_requested = config.getoption("--uitests")
|
||||||
|
|
||||||
|
# Unless explicitly requested, ignore these tests
|
||||||
|
if "test_dist.py" in str(path):
|
||||||
|
return True
|
||||||
|
if "test_urls.py" in str(path):
|
||||||
|
return True
|
||||||
|
if "test_inject.py" in str(path):
|
||||||
|
return True
|
||||||
|
|
||||||
|
uitest_file = "tests/uitests" in str(path)
|
||||||
|
if uitest_file and not uitests_requested:
|
||||||
|
return True
|
||||||
|
if not uitest_file and uitests_requested:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_collection_modifyitems(config, items):
|
||||||
|
def find_items(basename):
|
||||||
|
return [i for i in items
|
||||||
|
if os.path.basename(i.fspath) == basename]
|
||||||
|
|
||||||
|
# Move test_cli cases to the end, because they are slow
|
||||||
|
# Move test_checkprops to the very end, because it needs to run
|
||||||
|
# after everything else to give proper results
|
||||||
|
cliitems = find_items("test_cli.py")
|
||||||
|
chkitems = find_items("test_checkprops.py")
|
||||||
|
|
||||||
|
for i in cliitems + chkitems:
|
||||||
|
items.remove(i)
|
||||||
|
items.append(i)
|
||||||
|
|
||||||
|
if not find_items("test_urls.py"):
|
||||||
|
# Don't setup urlfetcher mocking for test_urls.py
|
||||||
|
# All other tests need it
|
||||||
|
import tests.urlfetcher_mock
|
||||||
|
tests.urlfetcher_mock.setup_mock()
|
||||||
|
|
||||||
|
if find_items("test_inject.py"):
|
||||||
|
if not config.getoption("--capture") == "no":
|
||||||
|
pytest.fail("test_inject.py requires `pytest --capture=no`")
|
Loading…
Reference in New Issue
Block a user