- вот тут вы идете по словарю, добавляете ключ в лист expected_response_text, потом в него же переприсваете словарь харкодный - что тут по вашему должно произойти?
expected_response_text=[]
for i in UA:
expected_response_text.append(i)
expected_response_text = {'user_agent': 'Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30','platform': 'Mobile', 'browser': 'No', 'device': 'Android'}
@pytest.mark.parametrize('agent, platform, browser, device', UA)
def test_get_user_agent(self, agent, platform, browser, device):
url = "https://playground.learnqa.ru/ajax/api/user_agent_check"
UA = {"user-agent": agent}
response = requests.get(url, headers=UA)
parsed_response = response.json()
expected_response_text = {
'user_agent': agent,
'platform': platform,
'browser': browser,
'device': device
}
print(expected_response_text)
actual_response_text = parsed_response
print(actual_response_text)
assert not (result := compare(expected_response_text, actual_response_text)), result
# Условно у меня есть одна абстрация для всех классов, куда я сложил какие-то базовые вещи для всех.
@dataclass
class ApiAbstraction(ABC):
config: Any = field(init=True)
session: ClientSession = field(init=True, default_factory=ClientSession)
async def close(self):
await self.session.close()
# И есть разные классы, для авторизации и апи
@dataclass
class ApiBLABLA(ApiAbstraction):
# Загрузить файл
async def send_file(self, filepath: str):
endpoint = f"app/files"
new_url = urljoin(self.config.api, endpoint)
headers = {"accept": JSON}
file = os.path.abspath(filepath)
data = {"file": open(file, "r")}
raw_result = await self.session.post(new_url, headers=headers, data=data)
result = await raw_result.json()
response = get_response_instance(result)
if response.success:
file = FileUploadModel.init_from_data(response.result)
return file
return response
# Условно класс для авторизации
@dataclass
class Auth(ApiAbstraction):
async def login(self):
endpoint = "auth/blabla"
new_url = urljoin(self.config.auth, endpoint)
headers = {}
raw_response = await self.session.get(new_url, headers=headers)
content = await raw_response.json(content_type=None)
response = get_response_instance(content, AuthModel)
return response
# Для ответов у меня есть модели, в которые конвертируется JSON ответ. можно и напрямую работать, но нам захотелось через модели.
@dataclass
class AuthModel(AbstractClass):
key: str = ''
--dist=loadscope: tests will be grouped by module for test functions and by class for test methods, then each group will be sent to an available worker, guaranteeing that all tests in a group run in the same process. This can be useful if you have expensive module-level or class-level fixtures. Currently the groupings can’t be customized, with grouping by class takes priority over grouping by module. This feature was added in version 1.19.
--dist=loadfile: tests will be grouped by file name, and then will be sent to an available worker, guaranteeing that all tests in a group run in the same worker. This feature was added in version 1.21.
return element.click()
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
def get_element(self, path_type, element_path, custom_time_out=None,):
"""
:param path_type: тип локатора
:param element_path: путь элемента
:return:
"""
__type = {
'xpath': By.XPATH,
'css': By.CSS_SELECTOR,
'id': By.ID,
'class': By.CLASS_NAME
}
if custom_time_out is not None:
time_out = custom_time_out
else:
time_out = self.time_out
return WebDriverWait(self.driver, time_out).until(expected_conditions.presence_of_element_located((__type.get(path_type), element_path)))