Skip to content

Commit d9bf25e

Browse files
authored
Removed reset_log_levels fixture (#1004)
1 parent a07b1b9 commit d9bf25e

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

tests/conftest.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import logging
43
import os
54
import shutil
65
from collections.abc import Iterator
@@ -136,22 +135,3 @@ def stub_data_dir_w_near_dupes(stub_data_dir: Path, tmp_path: Path) -> Iterator[
136135

137136
if tmp_path.exists():
138137
shutil.rmtree(tmp_path, ignore_errors=True)
139-
140-
141-
@pytest.fixture(name="reset_log_levels")
142-
def fixture_reset_log_levels(caplog) -> Iterator[None]:
143-
logging.getLogger().setLevel(logging.DEBUG)
144-
145-
for name in logging.root.manager.loggerDict:
146-
logger = logging.getLogger(name)
147-
logger.setLevel(logging.DEBUG)
148-
logger.propagate = True
149-
150-
caplog.set_level(logging.DEBUG)
151-
152-
yield
153-
154-
for name in logging.root.manager.loggerDict:
155-
logger = logging.getLogger(name)
156-
logger.setLevel(logging.NOTSET)
157-
logger.propagate = True

tests/test_clients.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,9 @@ def test_bad_init() -> None:
531531

532532

533533
@pytest.mark.vcr
534-
@pytest.mark.usefixtures("reset_log_levels")
535534
@pytest.mark.asyncio
536535
async def test_ensure_sequential_run(caplog) -> None:
537-
caplog.set_level(logging.DEBUG)
536+
caplog.set_level(logging.DEBUG, logger=paperqa.clients.__name__)
538537
# were using a DOI that is NOT in crossref, but running the crossref client first
539538
# we will ensure that both are run sequentially
540539

@@ -552,14 +551,18 @@ async def test_ensure_sequential_run(caplog) -> None:
552551
fields=["doi", "title"],
553552
)
554553
assert details, "Should find the right DOI in the second client"
555-
record_indices = {"crossref": -1, "semantic_scholar": -1}
554+
record_indices: dict[str, list[int]] = {"crossref": [], "semantic_scholar": []}
556555
for n, record in enumerate(caplog.records):
556+
if not record.name.startswith(paperqa.__name__): # Skip non-PQA logs
557+
continue
557558
if "CrossrefProvider" in record.msg:
558-
record_indices["crossref"] = n
559+
record_indices["crossref"].append(n)
559560
if "SemanticScholarProvider" in record.msg:
560-
record_indices["semantic_scholar"] = n
561+
record_indices["semantic_scholar"].append(n)
562+
assert record_indices["crossref"], "Crossref should run"
563+
assert record_indices["semantic_scholar"], "Semantic Scholar should run"
561564
assert (
562-
record_indices["crossref"] < record_indices["semantic_scholar"]
565+
record_indices["crossref"][-1] < record_indices["semantic_scholar"][-1]
563566
), "Crossref should run first"
564567

565568
non_clobbered_details = await client.query(
@@ -574,10 +577,9 @@ async def test_ensure_sequential_run(caplog) -> None:
574577

575578

576579
@pytest.mark.vcr
577-
@pytest.mark.usefixtures("reset_log_levels")
578580
@pytest.mark.asyncio
579581
async def test_ensure_sequential_run_early_stop(caplog) -> None:
580-
caplog.set_level(logging.DEBUG)
582+
caplog.set_level(logging.DEBUG, logger=paperqa.clients.__name__)
581583
# now we should stop after hitting s2
582584
async with aiohttp.ClientSession() as session:
583585
client = DocMetadataClient(
@@ -593,21 +595,23 @@ async def test_ensure_sequential_run_early_stop(caplog) -> None:
593595
fields=["doi", "title"],
594596
)
595597
assert details, "Should find the right DOI in the second client"
596-
record_indices = {"crossref": -1, "semantic_scholar": -1, "early_stop": -1}
598+
record_indices: dict[str, list[int]] = {
599+
"crossref": [],
600+
"semantic_scholar": [],
601+
"early_stop": [],
602+
}
597603
for n, record in enumerate(caplog.records):
604+
if not record.name.startswith(paperqa.__name__): # Skip non-PQA logs
605+
continue
598606
if "CrossrefProvider" in record.msg:
599-
record_indices["crossref"] = n
607+
record_indices["crossref"].append(n)
600608
if "SemanticScholarProvider" in record.msg:
601-
record_indices["semantic_scholar"] = n
609+
record_indices["semantic_scholar"].append(n)
602610
if "stopping early." in record.msg:
603-
record_indices["early_stop"] = n
604-
assert (
605-
record_indices["crossref"] == -1
606-
), "Crossref should be index -1 i.e. not found"
607-
assert (
608-
record_indices["semantic_scholar"] != -1
609-
), "Semantic Scholar should be found"
610-
assert record_indices["early_stop"] != -1, "We should stop early."
611+
record_indices["early_stop"].append(n)
612+
assert not record_indices["crossref"], "Crossref should not have run"
613+
assert record_indices["semantic_scholar"], "Semantic Scholar should have run"
614+
assert record_indices["early_stop"], "We should stop early"
611615

612616

613617
@pytest.mark.vcr

0 commit comments

Comments
 (0)