refactor(pytest): PytestNeotestAdapter (#24)

Having `NeotestResultCollector` (a pytest plugin) as a inner local
class would make the code a bit difficult to read due to quite much
indentation. This commit does refactoring on NeotestResultCollector
to make it a module-level class with a reference to NeotestAdapter.

This refactoring would make easier adding more pytest plugins
(e.g., debugger integration) in the future.

There should be no changes in behaviors.
This commit is contained in:
Jongwook Choi
2022-10-29 08:23:40 -04:00
committed by GitHub
parent 9e2db9375c
commit 2dc9c95fe9
3 changed files with 107 additions and 85 deletions

View File

@@ -1,5 +1,6 @@
import abc
from enum import Enum
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Callable, Dict, List, Optional
class NeotestResultStatus(str, Enum):
@@ -29,7 +30,8 @@ else:
NeotestResult = Dict
class NeotestAdapter:
class NeotestAdapter(abc.ABC):
def update_result(
self, base: Optional[NeotestResult], update: NeotestResult
) -> NeotestResult:
@@ -40,3 +42,8 @@ class NeotestAdapter:
"errors": (base.get("errors") or []) + (update.get("errors") or []) or None,
"short": (base.get("short") or "") + (update.get("short") or ""),
}
@abc.abstractmethod
def run(self, args: List[str], stream: Callable):
del args, stream
raise NotImplementedError