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

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

anthonywritescode

4 года назад

14,554 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@issecret1
@issecret1 - 14.02.2023 08:18

This was very helpful, thanks

Ответить
@vasiliykorn4485
@vasiliykorn4485 - 10.11.2022 18:33

rly halpfull, thanks

Ответить
@Sindoku
@Sindoku - 17.10.2022 08:26

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

Ответить
@essamgouda1609
@essamgouda1609 - 26.05.2022 19:28

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

Ответить
@amirhessamtahmassebi678
@amirhessamtahmassebi678 - 25.05.2022 19:56

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,
)

Ответить
@adityahpatel
@adityahpatel - 19.04.2022 00:24

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

Ответить
@samsilver3232
@samsilver3232 - 09.04.2022 21:04

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

Ответить
@talalkalai8748
@talalkalai8748 - 03.03.2022 08:37

pytest xdist video? any other parallelization mechanism for pytest?

Ответить
@kushashwaraviShrimali
@kushashwaraviShrimali - 20.02.2022 18:40

Short, concise and accurate! Well done man.

Ответить
@apoorvagupta9634
@apoorvagupta9634 - 30.06.2021 11:00

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

Ответить
@tejaswiniveerashetty6625
@tejaswiniveerashetty6625 - 24.06.2021 23:48

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

Ответить
@apdy27
@apdy27 - 15.05.2020 16:08

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!💜

Ответить
@McSinyx
@McSinyx - 15.05.2020 11:54

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)

Ответить