Skip to content
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

Can I import ward tests from another library? #308

Open
kajuberdut opened this issue Nov 9, 2021 · 2 comments
Open

Can I import ward tests from another library? #308

kajuberdut opened this issue Nov 9, 2021 · 2 comments

Comments

@kajuberdut
Copy link

I have a number of libraries that share several hundred common tests. Is there any sane way for me to factor these tests into a separate python module and import them into each library?

@kajuberdut
Copy link
Author

kajuberdut commented Nov 10, 2021

This might not be the greatest solution but I have found that it does work: Create the shared tests as a ward plugin:

import typing as t
from pathlib import Path

from my_library import module_containing_tests
from ward._collect import (
    get_info_for_modules,
    get_tests_in_modules,
    load_modules,
)
from ward.config import Config
from ward.hooks import hook
from ward.testing import Test


@hook
def preprocess_tests(config: Config, collected_tests t.List[Test]) -> None:
    paths = [Path(module_containing_tests.__file__)]
    mod_infos = get_info_for_modules(paths, ())
    modules = load_modules(mod_infos)
    if modules:
        collected_tests.extend(get_tests_in_modules(modules, True))

Leaving this issue open in case there is meaningful feedback on this approach.

@WolfDWyc
Copy link

WolfDWyc commented Dec 9, 2023

What if you made a function in which the tests are defined (e.g. make_tests) and call it in each library you want to use the tests in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants