Skip to content

Update imports in tests. #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`540` changes the CLI entry-point and allow `pytask.build(tasks=task_func)` as
the signatures suggested.
- {pull}`542` refactors the plugin manager.
- {pull}`543` fixes imports in tests and related issues.

## 0.4.4 - 2023-12-04

Expand Down
5 changes: 4 additions & 1 deletion src/pytask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from _pytask.build import build
from _pytask.capture_utils import CaptureMethod
from _pytask.capture_utils import ShowCapture
from _pytask.cli import cli
from _pytask.click import ColoredCommand
from _pytask.click import ColoredGroup
from _pytask.click import EnumChoice
Expand Down Expand Up @@ -76,6 +75,10 @@
from _pytask.warnings_utils import warning_record_to_str
from _pytask.warnings_utils import WarningReport

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

__all__ = [
"BaseTable",
Expand Down
12 changes: 11 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from __future__ import annotations

import os
import re
import sys
from contextlib import contextmanager
from pathlib import Path
from typing import Any

import pytest
from _pytask.pluginmanager import storage
from click.testing import CliRunner
from nbmake.pytest_items import NotebookItem
from packaging import version
from pytask import console
from pytask import storage


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -106,3 +108,11 @@ def invoke(self, *args, **kwargs):
@pytest.fixture()
def runner():
return CustomCliRunner()


def pytest_collection_modifyitems(session, config, items) -> None: # noqa: ARG001
"""Add markers to Jupyter notebook tests."""
if sys.platform == "debian" and "CI" in os.environ: # pragma: no cover
for item in items:
if isinstance(item, NotebookItem):
item.add_marker(pytest.mark.xfail(reason="Fails regularly on MacOS"))
4 changes: 2 additions & 2 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import pytest
from _pytask.collect import _find_shortest_uniquely_identifiable_name_for_tasks
from _pytask.collect import pytask_collect_node
from _pytask.exceptions import NodeNotCollectedError
from _pytask.models import NodeInfo
from pytask import build
from pytask import cli
from pytask import CollectionOutcome
from pytask import ExitCode
from pytask import NodeInfo
from pytask import NodeNotCollectedError
from pytask import Session
from pytask import Task

Expand Down
2 changes: 1 addition & 1 deletion tests/test_collect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import pytest
from _pytask.collect_command import _find_common_ancestor_of_all_nodes
from _pytask.collect_command import _print_collected_tasks
from _pytask.nodes import PathNode
from attrs import define
from pytask import cli
from pytask import ExitCode
from pytask import PathNode
from pytask import Task


Expand Down
2 changes: 1 addition & 1 deletion tests/test_collect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from _pytask.collect_utils import _find_args_with_product_annotation
from _pytask.collect_utils import _merge_dictionaries
from _pytask.collect_utils import _Placeholder
from _pytask.typing import Product # noqa: TCH002
from pytask import depends_on
from pytask import produces
from pytask import Product
from typing_extensions import Annotated


Expand Down
6 changes: 3 additions & 3 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import textwrap

import pytest
from _pytask.database_utils import create_database
from _pytask.database_utils import DatabaseSession
from _pytask.database_utils import State
from pytask import build
from pytask import cli
from pytask import create_database
from pytask import DatabaseSession
from pytask import ExitCode
from pytask import State
from pytask.path import hash_path
from sqlalchemy.engine import make_url

Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def task_example() -> Annotated[Dict[str, str], nodes]:
@pytest.mark.end_to_end()
def test_execute_tasks_and_pass_values_only_by_python_nodes(runner, tmp_path):
source = """
from _pytask.nodes import PathNode
from pytask import PathNode
from pytask import PythonNode
from typing_extensions import Annotated
from pathlib import Path
Expand Down
5 changes: 5 additions & 0 deletions tests/test_hook_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pytask import ExitCode


@pytest.mark.end_to_end()
@pytest.mark.parametrize(
"module_name",
[
Expand Down Expand Up @@ -55,6 +56,7 @@ def pytask_extend_command_line_interface(cli):
assert "--new-option" in result.stdout.decode()


@pytest.mark.end_to_end()
@pytest.mark.parametrize(
"module_name",
[
Expand Down Expand Up @@ -100,6 +102,7 @@ def pytask_extend_command_line_interface(cli):
assert "--new-option" in result.stdout.decode()


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


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


@pytest.mark.end_to_end()
def test_error_when_hook_module_is_no_iterable(tmp_path):
tmp_path.joinpath("pyproject.toml").write_text(
"[tool.pytask.ini_options]\nhook_module = 'hooks'"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import pytest
from _pytask.live import LiveExecution
from _pytask.live import LiveManager
from _pytask.reports import ExecutionReport
from pytask import cli
from pytask import ExecutionReport
from pytask import ExitCode
from pytask import Task
from pytask import TaskOutcome
Expand Down
4 changes: 2 additions & 2 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from _pytask.logging import _format_plugin_names_and_versions
from _pytask.logging import _humanize_time
from _pytask.logging import pytask_log_session_footer
from _pytask.outcomes import ExitCode
from _pytask.outcomes import TaskOutcome
from pytask import cli
from pytask import ExitCode
from pytask import TaskOutcome


class DummyDist(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mark_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytask
import pytest
from _pytask.models import CollectionMetadata
from pytask import CollectionMetadata
from pytask import get_all_marks
from pytask import get_marks
from pytask import has_mark
Expand Down
4 changes: 2 additions & 2 deletions tests/test_outcomes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import pytest
from _pytask.reports import CollectionReport
from _pytask.reports import ExecutionReport
from pytask import CollectionOutcome
from pytask import CollectionReport
from pytask import count_outcomes
from pytask import ExecutionReport
from pytask import TaskOutcome


Expand Down
2 changes: 1 addition & 1 deletion tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from _pytask.path import find_case_sensitive_path
from _pytask.path import find_closest_ancestor
from _pytask.path import find_common_ancestor
from _pytask.path import import_path
from _pytask.path import relative_to
from pytask.path import import_path


@pytest.mark.unit()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import textwrap

import pytest
from _pytask.database_utils import State
from _pytask.path import hash_path
from _pytask.persist import pytask_execute_task_process_report
from pytask import build
from pytask import create_database
from pytask import DatabaseSession
from pytask import ExitCode
from pytask import Persisted
from pytask import SkippedUnchanged
from pytask import State
from pytask import TaskOutcome
from pytask.path import hash_path

from tests.conftest import restore_sys_path_and_module_after_test_execution

Expand Down
4 changes: 2 additions & 2 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import textwrap

import pytest
from _pytask.cli import cli
from _pytask.profile import _to_human_readable_size
from _pytask.profile import Runtime
from pytask import build
from pytask import cli
from pytask import create_database
from pytask import DatabaseSession
from pytask import ExitCode
from pytask import Runtime


@pytest.mark.end_to_end()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from contextlib import ExitStack as does_not_raise # noqa: N813

import pytest
from _pytask.outcomes import ExitCode
from _pytask.shared import convert_to_enum
from _pytask.shared import find_duplicates
from pytask import build
from pytask import ExitCode
from pytask import ShowCapture


Expand Down
2 changes: 1 addition & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def func():
source = """
from pytask import task
from pathlib import Path
from _pytask.path import import_path
from pytask.path import import_path
import inspect

_ROOT_PATH = Path(__file__).parent
Expand Down
8 changes: 4 additions & 4 deletions tests/test_tree_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import textwrap

import pytest
from _pytask.outcomes import ExitCode
from _pytask.tree_util import tree_map
from _pytask.tree_util import tree_structure
from pytask import build
from pytask import cli
from pytask import ExitCode
from pytask.tree_util import tree_map
from pytask.tree_util import tree_structure


@pytest.mark.end_to_end()
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_profile_with_pytree(tmp_path, runner):
source = """
import time
import pytask
from _pytask.tree_util import tree_leaves
from pytask.tree_util import tree_leaves

@pytask.mark.produces([{"out_1": "out_1.txt"}, {"out_2": "out_2.txt"}])
def task_example(produces):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import functools

import pytest
from _pytask.typing import is_task_function
from pytask import is_task_function


@pytest.mark.unit()
Expand Down