Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants