Skip to content

Commit 0d2749b

Browse files
authored
Update imports in tests. (#543)
1 parent d9cd023 commit 0d2749b

20 files changed

+47
-28
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2828
- {pull}`540` changes the CLI entry-point and allow `pytask.build(tasks=task_func)` as
2929
the signatures suggested.
3030
- {pull}`542` refactors the plugin manager.
31+
- {pull}`543` fixes imports in tests and related issues.
3132

3233
## 0.4.4 - 2023-12-04
3334

src/pytask/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from _pytask.build import build
77
from _pytask.capture_utils import CaptureMethod
88
from _pytask.capture_utils import ShowCapture
9-
from _pytask.cli import cli
109
from _pytask.click import ColoredCommand
1110
from _pytask.click import ColoredGroup
1211
from _pytask.click import EnumChoice
@@ -76,6 +75,10 @@
7675
from _pytask.warnings_utils import warning_record_to_str
7776
from _pytask.warnings_utils import WarningReport
7877

78+
# _pytask.cli needs to be imported last because it triggers extending the cli and
79+
# therefore loading plugins which will attempt to import modules that might only be
80+
# partially initialized. Maybe not here, but definitely for plugins.
81+
from _pytask.cli import cli # noreorder
7982

8083
__all__ = [
8184
"BaseTable",

tests/conftest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from __future__ import annotations
22

3+
import os
34
import re
45
import sys
56
from contextlib import contextmanager
67
from pathlib import Path
78
from typing import Any
89

910
import pytest
10-
from _pytask.pluginmanager import storage
1111
from click.testing import CliRunner
12+
from nbmake.pytest_items import NotebookItem
1213
from packaging import version
1314
from pytask import console
15+
from pytask import storage
1416

1517

1618
@pytest.fixture(autouse=True)
@@ -106,3 +108,11 @@ def invoke(self, *args, **kwargs):
106108
@pytest.fixture()
107109
def runner():
108110
return CustomCliRunner()
111+
112+
113+
def pytest_collection_modifyitems(session, config, items) -> None: # noqa: ARG001
114+
"""Add markers to Jupyter notebook tests."""
115+
if sys.platform == "debian" and "CI" in os.environ: # pragma: no cover
116+
for item in items:
117+
if isinstance(item, NotebookItem):
118+
item.add_marker(pytest.mark.xfail(reason="Fails regularly on MacOS"))

tests/test_collect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import pytest
99
from _pytask.collect import _find_shortest_uniquely_identifiable_name_for_tasks
1010
from _pytask.collect import pytask_collect_node
11-
from _pytask.exceptions import NodeNotCollectedError
12-
from _pytask.models import NodeInfo
1311
from pytask import build
1412
from pytask import cli
1513
from pytask import CollectionOutcome
1614
from pytask import ExitCode
15+
from pytask import NodeInfo
16+
from pytask import NodeNotCollectedError
1717
from pytask import Session
1818
from pytask import Task
1919

tests/test_collect_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import pytest
1010
from _pytask.collect_command import _find_common_ancestor_of_all_nodes
1111
from _pytask.collect_command import _print_collected_tasks
12-
from _pytask.nodes import PathNode
1312
from attrs import define
1413
from pytask import cli
1514
from pytask import ExitCode
15+
from pytask import PathNode
1616
from pytask import Task
1717

1818

tests/test_collect_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from _pytask.collect_utils import _find_args_with_product_annotation
1313
from _pytask.collect_utils import _merge_dictionaries
1414
from _pytask.collect_utils import _Placeholder
15-
from _pytask.typing import Product # noqa: TCH002
1615
from pytask import depends_on
1716
from pytask import produces
17+
from pytask import Product
1818
from typing_extensions import Annotated
1919

2020

tests/test_database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import textwrap
44

55
import pytest
6-
from _pytask.database_utils import create_database
7-
from _pytask.database_utils import DatabaseSession
8-
from _pytask.database_utils import State
96
from pytask import build
107
from pytask import cli
8+
from pytask import create_database
9+
from pytask import DatabaseSession
1110
from pytask import ExitCode
11+
from pytask import State
1212
from pytask.path import hash_path
1313
from sqlalchemy.engine import make_url
1414

tests/test_execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def task_example() -> Annotated[Dict[str, str], nodes]:
683683
@pytest.mark.end_to_end()
684684
def test_execute_tasks_and_pass_values_only_by_python_nodes(runner, tmp_path):
685685
source = """
686-
from _pytask.nodes import PathNode
686+
from pytask import PathNode
687687
from pytask import PythonNode
688688
from typing_extensions import Annotated
689689
from pathlib import Path

tests/test_hook_module.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pytask import ExitCode
1010

1111

12+
@pytest.mark.end_to_end()
1213
@pytest.mark.parametrize(
1314
"module_name",
1415
[
@@ -55,6 +56,7 @@ def pytask_extend_command_line_interface(cli):
5556
assert "--new-option" in result.stdout.decode()
5657

5758

59+
@pytest.mark.end_to_end()
5860
@pytest.mark.parametrize(
5961
"module_name",
6062
[
@@ -100,6 +102,7 @@ def pytask_extend_command_line_interface(cli):
100102
assert "--new-option" in result.stdout.decode()
101103

102104

105+
@pytest.mark.end_to_end()
103106
def test_error_when_hook_module_path_does_not_exist(tmp_path):
104107
result = subprocess.run( # noqa: PLW1510
105108
("pytask", "build", "--hook-module", "hooks.py", "--help"),
@@ -110,6 +113,7 @@ def test_error_when_hook_module_path_does_not_exist(tmp_path):
110113
assert b"Error: Invalid value for '--hook-module'" in result.stderr
111114

112115

116+
@pytest.mark.end_to_end()
113117
def test_error_when_hook_module_module_does_not_exist(tmp_path):
114118
result = subprocess.run( # noqa: PLW1510
115119
("pytask", "build", "--hook-module", "hooks", "--help"),
@@ -120,6 +124,7 @@ def test_error_when_hook_module_module_does_not_exist(tmp_path):
120124
assert b"Error: Invalid value for '--hook-module':" in result.stderr
121125

122126

127+
@pytest.mark.end_to_end()
123128
def test_error_when_hook_module_is_no_iterable(tmp_path):
124129
tmp_path.joinpath("pyproject.toml").write_text(
125130
"[tool.pytask.ini_options]\nhook_module = 'hooks'"

tests/test_live.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import pytest
77
from _pytask.live import LiveExecution
88
from _pytask.live import LiveManager
9-
from _pytask.reports import ExecutionReport
109
from pytask import cli
10+
from pytask import ExecutionReport
1111
from pytask import ExitCode
1212
from pytask import Task
1313
from pytask import TaskOutcome

tests/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from _pytask.logging import _format_plugin_names_and_versions
99
from _pytask.logging import _humanize_time
1010
from _pytask.logging import pytask_log_session_footer
11-
from _pytask.outcomes import ExitCode
12-
from _pytask.outcomes import TaskOutcome
1311
from pytask import cli
12+
from pytask import ExitCode
13+
from pytask import TaskOutcome
1414

1515

1616
class DummyDist(NamedTuple):

tests/test_mark_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytask
66
import pytest
7-
from _pytask.models import CollectionMetadata
7+
from pytask import CollectionMetadata
88
from pytask import get_all_marks
99
from pytask import get_marks
1010
from pytask import has_mark

tests/test_outcomes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

33
import pytest
4-
from _pytask.reports import CollectionReport
5-
from _pytask.reports import ExecutionReport
64
from pytask import CollectionOutcome
5+
from pytask import CollectionReport
76
from pytask import count_outcomes
7+
from pytask import ExecutionReport
88
from pytask import TaskOutcome
99

1010

tests/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from _pytask.path import find_case_sensitive_path
1616
from _pytask.path import find_closest_ancestor
1717
from _pytask.path import find_common_ancestor
18-
from _pytask.path import import_path
1918
from _pytask.path import relative_to
19+
from pytask.path import import_path
2020

2121

2222
@pytest.mark.unit()

tests/test_persist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import textwrap
44

55
import pytest
6-
from _pytask.database_utils import State
7-
from _pytask.path import hash_path
86
from _pytask.persist import pytask_execute_task_process_report
97
from pytask import build
108
from pytask import create_database
119
from pytask import DatabaseSession
1210
from pytask import ExitCode
1311
from pytask import Persisted
1412
from pytask import SkippedUnchanged
13+
from pytask import State
1514
from pytask import TaskOutcome
15+
from pytask.path import hash_path
1616

1717
from tests.conftest import restore_sys_path_and_module_after_test_execution
1818

tests/test_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import textwrap
44

55
import pytest
6-
from _pytask.cli import cli
76
from _pytask.profile import _to_human_readable_size
8-
from _pytask.profile import Runtime
97
from pytask import build
8+
from pytask import cli
109
from pytask import create_database
1110
from pytask import DatabaseSession
1211
from pytask import ExitCode
12+
from pytask import Runtime
1313

1414

1515
@pytest.mark.end_to_end()

tests/test_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from contextlib import ExitStack as does_not_raise # noqa: N813
55

66
import pytest
7-
from _pytask.outcomes import ExitCode
87
from _pytask.shared import convert_to_enum
98
from _pytask.shared import find_duplicates
109
from pytask import build
10+
from pytask import ExitCode
1111
from pytask import ShowCapture
1212

1313

tests/test_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def func():
708708
source = """
709709
from pytask import task
710710
from pathlib import Path
711-
from _pytask.path import import_path
711+
from pytask.path import import_path
712712
import inspect
713713
714714
_ROOT_PATH = Path(__file__).parent

tests/test_tree_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import textwrap
55

66
import pytest
7-
from _pytask.outcomes import ExitCode
8-
from _pytask.tree_util import tree_map
9-
from _pytask.tree_util import tree_structure
107
from pytask import build
118
from pytask import cli
9+
from pytask import ExitCode
10+
from pytask.tree_util import tree_map
11+
from pytask.tree_util import tree_structure
1212

1313

1414
@pytest.mark.end_to_end()
@@ -52,7 +52,7 @@ def test_profile_with_pytree(tmp_path, runner):
5252
source = """
5353
import time
5454
import pytask
55-
from _pytask.tree_util import tree_leaves
55+
from pytask.tree_util import tree_leaves
5656
5757
@pytask.mark.produces([{"out_1": "out_1.txt"}, {"out_2": "out_2.txt"}])
5858
def task_example(produces):

tests/test_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import functools
44

55
import pytest
6-
from _pytask.typing import is_task_function
6+
from pytask import is_task_function
77

88

99
@pytest.mark.unit()

0 commit comments

Comments
 (0)