I am using Hypothesis to unit test my package. There are some functions in my package that I only want to run a few examples over for testing. I do not want Hypothesis to generate examples for me.
If I do the following:
@example(s="hello world")
@example(s="hello world 2")
def test_test(s):
assert len(s) > 0
and run pytest, PyTest complains that fixture 's' not found. I am not sure what the most elegant solution for this is. Cheers.
While it seems like for your particular case you wish to write tests with explicit data that doesn't use any data generation from hypothesis, you might be better off writing explicit tests named to reflect the data and expectations you are testing with.
e.g.
However, to help meet the requirement you are trying to achieve, perhaps you can do something like this (typically I'd always have a base strategy when adding explicit examples, so this is not something I typically do):
By using one_of and just, you can then simply pass them in to your
givenand you can test each of those. You can see from the code sample below, that the following will/should pass as it will only generate the provided three examples.It is important to note of a warning in the documentation when using
just: