dosage/tests/modules/conftest.py

59 lines
1.8 KiB
Python
Raw Normal View History

# SPDX-License-Identifier: MIT
2023-06-01 22:07:26 +00:00
# SPDX-FileCopyrightText: © 2004 Tristan Seligmann and Jonathan Jacobs
# SPDX-FileCopyrightText: © 2012 Bastian Kleineidam
# SPDX-FileCopyrightText: © 2015 Tobias Gruetzmacher
import re
import os
from operator import attrgetter
import pytest
from xdist.dsession import LoadScopeScheduling
from dosagelib.scraper import scrapers
def get_test_scrapers():
"""Return scrapers that should be tested."""
2021-04-02 08:15:18 +00:00
if 'TESTALL' in os.environ:
# test all comics (this will take some time)
# Ignore known-broken (and never-to-be-fixed) modules
scraper_pattern = '^(?!Schuelert)'
2021-04-02 08:15:18 +00:00
elif 'TESTCOMICS' in os.environ:
scraper_pattern = os.environ['TESTCOMICS']
else:
2020-04-18 11:03:02 +00:00
# Get limited number of scraper tests as default
testscrapernames = [
# "classic" BasicScraper
2020-04-18 11:03:02 +00:00
'AbstruseGoose',
# complex ParserScraper
2020-04-18 11:03:02 +00:00
'GoComics/CalvinAndHobbes',
# WordPressScraper
'GrrlPower',
]
2021-04-02 08:15:18 +00:00
scraper_pattern = '^(' + '|'.join(testscrapernames) + ')$'
2020-04-18 11:03:02 +00:00
2021-04-02 08:15:18 +00:00
matcher = re.compile(scraper_pattern)
2020-04-18 11:03:02 +00:00
return [
2022-06-04 08:56:25 +00:00
scraperobj for scraperobj in scrapers.all()
2021-04-02 08:15:18 +00:00
if matcher.match(scraperobj.name)
2020-04-18 11:03:02 +00:00
]
def pytest_generate_tests(metafunc):
if 'scraperobj' in metafunc.fixturenames:
scrapers = sorted(get_test_scrapers(), key=attrgetter('name'))
metafunc.parametrize('scraperobj', scrapers, ids=attrgetter('name'))
class LoadModScheduling(LoadScopeScheduling):
"""Implement load scheduling for comic modules. See xdist for details."""
def _split_scope(self, nodeid):
mod, test = nodeid.split("::", 1)
return mod + "::" + test.split("/", 1)[0]
2023-06-01 22:07:26 +00:00
@pytest.hookimpl(trylast=True)
def pytest_xdist_make_scheduler(config, log):
return LoadModScheduling(config, log)