Skip to content

Pytest test working with different versions of program #10175

Answered by The-Compiler
hmfkzh asked this question in Q&A
Discussion options

You must be logged in to vote

A perhaps slightly simpler way to what @nicoddemus has shown would be to write a function returning the appropriate skipif mark, instead of hardcoding one to a variable:

def minmaxversion(min_str, max_str):
    minver = tuple(map(int, min_str.split(".")))
    maxver = tuple(map(int, max_str.split(".")))
    return pytest.mark.skipif(
        not minver <= myprogram.__versioninfo__ <= maxver,
        reason=f"versions {minver} to {maxver} are required"
    )

@minmaxversion("3.1", "6.1")
def test_function():
    ...

(your 3.2 and 6.1 would be floats, which are a weird way to represent version numbers - also, this is completely untested)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by hmfkzh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants