Closed simpletonDL closed 4 years ago
unfortunately fixtures run after test selection is done, so the markers you want to use for selection get added only after selection
but there is a trick i jsut remembered pytest.param(2, marks=pytest.mark.slow)
should allow you to set the marker in the parameters (untested, please crosscheck the docs)
Oh, it is interesting! Do you know, can I build array of such parameters in runtime? Exactly, I need to extract some file paths and I don't really want to hardcode them.
its possible to do the building of parameter lists in hooks, but it has to happen at collect time
it helps to create a pytest plugin that manages the related resources to both the pytest_generate_tests
hook and fixtures can share some objects with metadata
Okey, thank you very much) I try to parametrize tests with os.listdir
and it has worked. In future I also will try hook, that you suggested. Can you please tell me how create mark with string (like pyteset.mark.some_function(str)
) or it is not possible?
im not sure what you mean by that, pytest.mark.something("astring")
can work just fine
if thats still not clear, please make up a example so that i can better understand what you try
To be honest I am newbie in pytest, so I dont know what exactly means parameter "astring"
(as I understand you mark function with something
, but I don`t understand the parameter you passed). I want something like getattr(pytest.mark, some_variable_marker)
, and surprisingly it worked. So I think this isse can be closed. Thank you very much for the answers and quick response!)
Thanks, astring ist literally Just a random String without meaning
Hello, I have parameterized fixture and I want to mark function invocaions differently. So, for example:
But when I try to run marked test function, pytest doesn`t find them:
The solution that uses
pytest.mark.parametrize
decorator won`t suite me, because I need to get parameters in runtime. The second question is how to create markers using python string? So, I want to achive something likepytest.mark.gen_mark(str)
. My installed packages:Thanks in advance for your attention!