0

I know it's impossible to add more tests inside fixtures because they run at test time, and tests are generated at collection time.

But I want to be able to generate parameters to a test based on the path to the test function (to the module where test function is).

Basically, I want something like that:

@pytest.mark.parametrize(
    argnames='letter',
    argvalues=lambda request: list(zip(request.fspath)),
    indirect=True
)
def test_foo(letter):
  assert letter

It should print put a path to the module, letter by letter as a parameter to the function:

foo[/]
foo[t]
foo[e]
foo[s]
foo[t]
foo[.]
foo[p]
foo[y]

This code (above) is definitively not working, but may be there is a way to use fspath as an argument to parametrize?

George Shuklin
  • 6,952
  • 10
  • 39
  • 80
  • `list(zip(__file__))`? Or `list(zip(pathlib.Path(__file__).name))`, whatever part of the module file name you need. – hoefling Dec 07 '20 at 21:32
  • Yes, probably, I'll stick with `__file__`. For test decorator it's enough. I thought about using it inside an external function (instead of `lambda`, and that function may be in a different module than a test, so fspath is needed. But it there is nothing else left, let it has `__file__` in a decorator. Thanks. – George Shuklin Dec 08 '20 at 08:15

0 Answers0