pytest's parametrize (beginner - intermediate) anthony explains #027

preview_player
Показать описание
today I explain pytest's parametrize which allows you to generate many tests from one test skeleton! Often referred to as table tests in other testing frameworks.

==========

I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Рекомендации по теме
Комментарии
Автор

Your pytest videos are very nice, short and straight to the point. Thank you !!

essamgouda
Автор

Short, concise and accurate! Well done man.

buffetCodes
Автор

The pytest.mark.parametrize decorator takes any iterable as the second parameter which made it easy for working through a lot of input and output for a game which were present in a file. Thanks for this!💜

apdy
Автор

thanks, this made me look up the doc and found really cool parametrizing examples! BTW a parameter type-hinted as float actually accept an int as well, that surprised me too the first time I saw it (the numeric tower, PEP 484)

McSinyx
Автор

Thanks for the names triple tip, that helps a lot!

Sindoku
Автор

pytest xdist video? any other parallelization mechanism for pytest?

talalkalai
Автор

How can I parametrize the whole class? Goal is to run the setup class and all the test cases for each value in the parametrized list

tejaswiniveerashetty
Автор

Is there any way to use the variable generated at run time ( suppose - self.id) to use as a parameter inside pytest.mark.parametrize?

apoorvagupta
Автор

Nice video, if my input to the test was a large json blob can I store this in conftest.py and import on run?

jakehobbyroyle
Автор

The pytest.param is awesome to learn about! I love parametrizing tests at work, but it's not always immediately obvious which test case failed in a parametrized test with like ~10 cases. :--) Do you have any blog posts/videos that you've loved that dive deep into intermediate+ pytest usage? Or do i just rtfm

_gunna
Автор

This is is easy because u only have 1 input and 1 expected output. What precisely to do when u have 3 inputs and 1 output? e.g. testing a function which adds 3 numbers

adityahpatel
Автор

Thanks; I am fan of using fixture_id
def _fixture_id(kwargs: Dict[str, Any]) -> str:
"""Returns a user-friendly test case from the parametrized kwargs.

Parameters

kwargs : Dict[str, Any]
Key-value pairs of test resources.

Returns

str
"""

return ", ".join(f"{k} : {v}" for (k, v) in kwargs.items())

and decorate the test with
@pytest.mark.parametrize(
"kwargs",
_load_test_cases_from_json(),
ids=_fixture_id,
)

amir.hessam