Meaning
...
Primary Function
...
Communicative Purpose
...
Pattern
@given(st.lists(st.; min_size=;))
Core Structure
@given(st.lists(st.; min_size=;))
Função primária
...
Propósito comunicativo
...
Situações de gatilho
...
Contextos
...
Padrão
@given(st.lists(st.; min_size=;))
Estrutura central
@given(st.lists(st.; min_size=;))
Slots de substituição
first slot: element generation strategy (e.g., st.integers(), st.text(), st.floats()); second slot: minimum list size (non-negative integer)
Colocados típicos
- @example for concrete test cases
- Settings to adjust test generation
- assume to filter inputs
Substituições comuns
- st.sets()
- st.tuples()
- or specifying max_size
- using st.lists(st.integers()) without min_size defaults to 0
Erros comuns
Forgetting to import st from hypothesis.strategies; using a non-integer for min_size; using mutable default strategies causing state leakage
Similar / contraste
@given(st.text()) for generating strings; @given(st.lists(st.integers(), min_size=1)) to forbid empty lists
Interferências
Coming from unittest: may expect explicit test loops; property-based testing replaces manual iteration with automatic generation
Família do chunk
- @given(st.text())
- @given(st.integers())
- @given(st.floats())
- @given(st.tuples(...))
Nuance
The strategy can be combined with st.one_of() or st.tuples(); large min_size may cause excessive generation time; Hypothesis may shrink failing examples
Efeito pragmático
Automates test data generation, increasing coverage and reducing boilerplate
Dica de memória
Think 'given' as 'given some random data'
Nota
The min_size parameter must be a non-negative integer; if max_size is set and less than min_size, Hypothesis will raise an InvalidArgument error during test execution.
Upgrade path
Add concrete examples with @example alongside @given, or use st.data() to draw more complex strategies during test execution
Log in to save chunks.