Sepertinya pola kode 100% pytest
Lihat:
https://docs.pytest.org/en/latest/fixture.html#conftest-py-sharing-fixture-functions
Saya memiliki masalah yang sama dengan, ini sebabnya saya menemukan posting ini;)
# ./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
Dan itu akan memperingatkan This inspection detects shadowing names defined in outer scopes.
Untuk memperbaikinya, cukup pindahkan twitter
perlengkapan ke./tests/conftest.py
# ./tests/conftest.py
import pytest
from syntropy import db
@pytest.fixture
def twitter():
twitter_ = db.Twitter()
twitter_._debug = True
return twitter_
Dan hapus twitter
fixture seperti di./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
Ini akan membuat QA, Pycharm, dan semua orang senang