7

Consider the following code:

fixtures.py

@pytest.fixture
def hello_world():
    return "Hello world!"

And then...

basic_tests.py

def test_says_hello(hello_world):
    assert hello_world == "Hello world!"

Now the thing is, pylance has no way of knowing that pytest will fill in my hello_world argument with whatever is the return value of hello_world() fixture. With things as simple as str, this can be done manually, but when dealing with many fixtures that return complex values, this is not just impractical for writing the code, but reading it as well.

Is there some way to extend the pytest functionality so that whenever it encounters an argument without explicit type, the correct type can be supplied? I am OK with writing the part that supplies the types, but I am not even sure I can change the pylance behavior or how to do that.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

0 Answers0