Учитывая, что у меня есть тест ниже:
class VideoGamesTest:
def test_create_a_new_videoGame(self):
protocol = 'http://'
domain = 'localhost:'
port = '8080'
path = '/app/videogames'
self.url = protocol+domain+port+path
response = requests.get(self.url,headers={'Accept': 'application/json'})
payload = {
"id": 16,
"name": "I am my Hero",
"releaseDate": "2020-02-21T16:54:03.200Z",
"reviewScore": 9.0,
"category": "Biography",
"rating": "9.0"
}
response = requests.post(self.url,data=json.dumps(payload),headers={'Content-Type': 'application/json'} )
response = json.loads(response.text)
assert 'status' in response.keys()
def test_get_all_videoGames(self):
protocol = 'http://'
domain = 'localhost:'
port = '8080'
path = '/app/videogames'
self.url = protocol+domain+port+path
response = requests.get(self.url,headers={'Accept': 'application/json'})
response = json.loads(response.text)[0]
print(response)
assert 'id' in response.keys()
Как вы видите, ниже часть повторяется:
protocol = 'http://'
domain = 'localhost:'
port = '8080'
path = '/app/videogames'
self.url = protocol+domain+port+path
Я не знаю, как рефакторинг этот класс, так что я могу иметь url
в качестве атрибута класса. Но, учитывая, что я не могу использовать __init__
в моем pytest
классе, тогда это не выполнимо.
Вопрос:
Как можно я пропускаю повторяющуюся часть тестов?