-
Notifications
You must be signed in to change notification settings - Fork 0
выполнил задания по 10 вебинару #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LinarKhmblov
wants to merge
3
commits into
master
Choose a base branch
from
HomeWork10
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
import datetime | ||
import time | ||
|
||
|
||
@pytest.fixture(scope='class', autouse=True) | ||
def setup_module(request): | ||
"""Записываем время запуска сессии тестов""" | ||
start_time = datetime.datetime.now().strftime('%d.%m %H:%M:%S') | ||
print(f'Запустили тест {start_time}!') | ||
|
||
def closure(): | ||
"""Записываем время завершения сессии тестов""" | ||
end_time = datetime.datetime.now().strftime('%d.%m %H:%M:%S') | ||
print(f'Тест завершился {end_time}.') | ||
|
||
request.addfinalizer(closure) | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def test_fixture(request): | ||
"""Записываем время запуска отдельного теста""" | ||
start_time = time.time() | ||
print('Тест запустился!') | ||
|
||
def closure(): | ||
"""Записываем время завершения отдельного тестов""" | ||
end_time = time.time() | ||
print(f'Тест завершился. Время выполнения {end_time - start_time} секунд.') | ||
|
||
request.addfinalizer(closure) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[pytest] | ||
|
||
markers = | ||
smoke: basic test | ||
negative: negative test | ||
by_zero | ||
my_fixture |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Напишите генератор generate_random_name(), используя модуль random, | ||
# который генерирует два слова из латинских букв от 1 до 15 символов, разделенных пробелами | ||
# Например при исполнении следующего кода: | ||
# gen = generate_random_name() | ||
# print(next(gen)) | ||
# print(next(gen)) | ||
# print(next(gen)) | ||
# print(next(gen)) | ||
# | ||
# Выводится: | ||
# tahxmckzexgdyt ocapwy | ||
# dxqebbukr jg | ||
# aym jpvezfqexlv | ||
# iuy qnikkgxvxfxtxv | ||
|
||
import random | ||
|
||
|
||
def generate_random_name(): | ||
max_lenght = 15 | ||
min_lenght = 1 | ||
|
||
def random_words(): | ||
lenght = random.randint(min_lenght, max_lenght) | ||
word = "" | ||
for _i in range(lenght): | ||
letter = chr(random.randint(97, 112)) | ||
word += letter | ||
return word | ||
|
||
while True: | ||
name = random_words() + " " + random_words() | ||
yield name | ||
|
||
gen = generate_random_name() | ||
print(next(gen)) | ||
print(next(gen)) | ||
print(next(gen)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Из набора тестов задания task_2 создайте один тест с параметрами, используя @pytest.mark.parametrize | ||
# Промаркируйте 1 параметр из выборки как smokе, а 1 набор данных скипните | ||
|
||
import pytest | ||
|
||
|
||
def all_division(*arg1): | ||
|
||
division = arg1[0] | ||
for i in arg1[1:]: | ||
division /= i | ||
return division | ||
|
||
@pytest.mark.parametrize('numbers', [ | ||
(10, 5), | ||
(100, 10, 5), | ||
pytest.param((100, 10, 2, 2), marks=pytest.mark.skip), | ||
(1000, 10, 5, 2, 2) | ||
]) | ||
@pytest.mark.parametrize('smoke', [True, False], ids=['smoke', 'not smoke']) | ||
def test_division(numbers, smoke): | ||
if smoke: | ||
pytest.skip('Пропускаем smoke тест.') | ||
expected_result = numbers[0] / numbers[1] | ||
for i in numbers[2:]: | ||
expected_result /= i | ||
assert all_division(*numbers) == expected_result | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Создайте класс с тестами и напишите фикстуры в conftest.py: | ||
# 1) Фикстуру для класса и используйте её. Например, печать времени начала выполнения класса с тестами и окончания | ||
# 2) Фикстуру для конкретного теста и используйте её не для всех тестов. Например, время выполнения теста. | ||
|
||
import pytest | ||
|
||
|
||
def all_division(*arg1): | ||
|
||
division = arg1[0] | ||
for i in arg1[1:]: | ||
division /= i | ||
return division | ||
|
||
|
||
@pytest.mark.my_fixture | ||
class TestAllDivision(): | ||
|
||
@pytest.mark.my_fixture | ||
def test_division_by_zero(self, test_fixture): | ||
with pytest.raises(ZeroDivisionError): | ||
assert all_division(1, 0) | ||
|
||
def test_division_two_numbers(self): | ||
assert all_division(4, 2) == 2 | ||
|
||
@pytest.mark.my_fixture | ||
def test_division_three_numbers(self, test_fixture): | ||
assert all_division(16, 4, 2) == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Напишите 5 тестов на функцию all_division. Обязательно должен быть тест деления на ноль. | ||
# Промаркируйте часть тестов. Например, smoke. | ||
# В консоли с помощью pytest сделайте вызов: | ||
# 1) Всех тестов | ||
# 2) Только с маркером smoke | ||
# 3) По маске. Выберите такую маску, чтобы под неё подпадали не все тесты, но больше одного | ||
# Пришлите на проверку файл с тестами, скрины с вызовами и их результаты. | ||
|
||
import pytest | ||
|
||
def all_division(*arg1): | ||
|
||
division = arg1[0] | ||
for i in arg1[1:]: | ||
division /= i | ||
return division | ||
|
||
# Тест деление двух чисел | ||
@pytest.mark.smoke | ||
def test_division_two_numbers(): | ||
assert all_division(25, 5) == 5 | ||
|
||
# Тест деление четырех чисел | ||
@pytest.mark.smoke | ||
def test_division_four_numbers(): | ||
assert all_division(99, 3, 11, 3) == 1 | ||
|
||
# Тест деление на ноль | ||
@pytest.mark.by_zero | ||
def test_division_by_zero(): | ||
with pytest.raises(ZeroDivisionError): | ||
assert all_division(1, 0) | ||
|
||
# Тест с аргументами, включающими строковое значение | ||
@pytest.mark.negative | ||
def test_division_by_string(): | ||
with pytest.raises(TypeError): | ||
assert all_division(10, '5') | ||
|
||
# Тест с аргументами, включающими строковое значение | ||
@pytest.mark.negative | ||
def test_division_by_not_int(): | ||
with pytest.raises(TypeError): | ||
assert all_division(5, [3, 4]) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
фикстуру для класса написал, но не использовал