Skip to content

Commit 96a0a26

Browse files
committed
format import, skip only unit tests when inlinetest-only is on
1 parent 0e39666 commit 96a0a26

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.0.2]
4+
### Fix
5+
- Fix: inlinetest-only skips collecting inline tests
6+
37
## [1.0.1]
48
### Added
59
- New README

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def read(fname):
1515

1616
setup(
1717
name="pytest-inline",
18-
version="1.0.1",
18+
version="1.0.2",
1919
author="Yu Liu",
2020
author_email="[email protected]",
2121
maintainer="Alan Han, Yu Liu, Pengyu Nie, Zachary William Thurston",

src/inline/plugin.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import ast
22
import copy
3+
import enum
34
import inspect
5+
import signal
46
import sys
57
import time
68
from pathlib import Path
79
from types import ModuleType
810
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
9-
import enum
11+
1012
import pytest
13+
from _pytest.main import Session
1114
from _pytest.pathlib import fnmatch_ex, import_path
15+
from _pytest.python import Package
1216
from pytest import Collector, Config, FixtureRequest, Parser
13-
import signal
14-
from _pytest.main import Session
1517

1618
if sys.version_info >= (3, 9, 0):
1719
from ast import unparse as ast_unparse
@@ -99,12 +101,12 @@ def pytest_configure(config):
99101

100102
@pytest.hookimpl()
101103
def pytest_collectstart(collector):
102-
if not isinstance(collector, Session):
104+
if not isinstance(collector, (Session, Package)):
103105
if collector.config.getoption("inlinetest_only") and (
104106
not isinstance(collector, InlinetestModule)
105107
):
106108
collector.collect = lambda: [] # type: ignore[assignment]
107-
elif collector.config.getoption("inlinetest_disable") and isinstance(
109+
if collector.config.getoption("inlinetest_disable") and isinstance(
108110
collector, InlinetestModule
109111
):
110112
collector.collect = lambda: [] # type: ignore[assignment]
@@ -122,8 +124,6 @@ def pytest_collect_file(
122124

123125

124126
def _is_inlinetest(config: Config, file_path: Path) -> bool:
125-
if config.getoption("inlinetest_disable"):
126-
return False
127127
globs = config.getoption("inlinetest_glob") or ["*.py"]
128128
return any(fnmatch_ex(glob, file_path) for glob in globs)
129129

@@ -1391,11 +1391,12 @@ def collect(self) -> Iterable[InlinetestItem]:
13911391
try:
13921392
# TODO: still need to find the right way to import without errors. mode=ImportMode.importlib did not work
13931393
module = import_path(self.path, root=self.config.rootpath)
1394-
except ImportError:
1394+
except (ImportError or ModuleNotFoundError) as e:
13951395
if self.config.getvalue("inlinetest_ignore_import_errors"):
13961396
pytest.skip("unable to import module %r" % self.path)
13971397
else:
13981398
raise ImportError("unable to import module %r" % self.path)
1399+
13991400
finder = InlineTestFinder()
14001401
runner = InlineTestRunner()
14011402

0 commit comments

Comments
 (0)