Il ressemble à un modèle de code 100% pytest
voir:
https://docs.pytest.org/en/latest/fixture.html#conftest-py-sharing-fixture-functions
J'ai eu le même problème, c'est pourquoi j'ai trouvé ce post;)
# ./tests/test_twitter1.py
import os
import pytest
from mylib import db
# ...
@pytest.fixture
def twitter():
twitter_ = db.Twitter()
twitter_._debug = True
return twitter_
@pytest.mark.parametrize("query,expected", [
("BANCO PROVINCIAL", 8),
("name", 6),
("castlabs", 42),
])
def test_search(twitter: db.Twitter, query: str, expected: int):
for query in queries:
res = twitter.search(query)
print(res)
assert res
Et il avertira This inspection detects shadowing names defined in outer scopes.
Pour résoudre ce problème, déplacez simplement votre twitter
appareil./tests/conftest.py
# ./tests/conftest.py
import pytest
from syntropy import db
@pytest.fixture
def twitter():
twitter_ = db.Twitter()
twitter_._debug = True
return twitter_
Et retirez le twitter
luminaire comme dans./tests/test_twitter2.py
# ./tests/test_twitter2.py
import os
import pytest
from mylib import db
# ...
@pytest.mark.parametrize("query,expected", [
("BANCO PROVINCIAL", 8),
("name", 6),
("castlabs", 42),
])
def test_search(twitter: db.Twitter, query: str, expected: int):
for query in queries:
res = twitter.search(query)
print(res)
assert res
Ce sera heureux QA, Pycharm et tout le monde