Skip to content

Support NamedTuples for named arguments in parametrizations. #224

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

Closed
2 tasks
tobiasraabe opened this issue Feb 23, 2022 · 1 comment
Closed
2 tasks

Support NamedTuples for named arguments in parametrizations. #224

tobiasraabe opened this issue Feb 23, 2022 · 1 comment
Labels
wontfix This will not be worked on

Comments

@tobiasraabe
Copy link
Member

Workarounds

typing.NamedTuple or collections.namedtuple can be used to achieve named arguments per iteration of the parametrization.

from pathlib import Path
from typing import NamedTuple


class Task(NamedTuple):
    depends_on: Path
    produces: Path


@pytask.mark.parametrize("depends_on, produces", [
    Task(depends_on="first_dataset.pkl", produces="first_plot.png"),
    Task(depends_on="second_dataset.pkl", produces="second_plot.png"),
])
def task_plot_data(depends_on, produces):
    df = pd.read_pickle(depends_on)
    ax = df.plot()
    plt.savefig(produces)
  • Document example usage in the documentation.
  • Implement a check for whether the arguments of the namedtuple match the signature of the parametrization.

Originally posted by @tobiasraabe in #206 (comment)

@tobiasraabe
Copy link
Member Author

This will not be pursued. #229 implements a new approach to parametrizations which will eventually supersede pytest's approach.

We keep this issue open for documentation. Probably until the pytest approach is deprecated.

@tobiasraabe tobiasraabe added the wontfix This will not be worked on label Mar 3, 2022
@tobiasraabe tobiasraabe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant