From b216171d908eedada4a1ba0fc15106ac5e1d570f Mon Sep 17 00:00:00 2001 From: Nataliia Date: Tue, 4 Oct 2022 14:59:32 +0300 Subject: [PATCH] added inspect --- tests/test_main.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 794a811c..19d7abf8 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,7 @@ import pytest +import inspect -from app.main import count_occurrences - +from app import main @pytest.mark.parametrize( "phrase,letter,count", @@ -15,16 +15,13 @@ ] ) def test_count_occurrences(phrase, letter, count): - assert count_occurrences(phrase, letter) == count, ( + assert main.count_occurrences(phrase, letter) == count, ( f"Function 'count_occurrences' should return {count}, " f"when 'phrase'='{phrase}' and 'letter'='{letter}'" ) - -def test_removed_comment(): - import app - with open(app.main.__file__, "r") as f: - file_content = f.read() - assert "# write your code here" not in file_content, \ - "You have to remove the unnecessary comment '# write your code here'" +def test_removed_comment(): + lines = inspect.getsource(main) + assert "# write your code here" not in lines, ("You have to" + " remove the unnecessary comment '# write your code here'")