diff --git a/tests/test_main.py b/tests/test_main.py index 794a811c..ab49b418 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,3 +1,5 @@ +import inspect + import pytest from app.main import count_occurrences @@ -12,7 +14,7 @@ ("Abracadabra", "A", 5), ("", "a", 0), ("Samsung", "b", 0), - ] + ], ) def test_count_occurrences(phrase, letter, count): assert count_occurrences(phrase, letter) == count, ( @@ -20,11 +22,9 @@ def test_count_occurrences(phrase, letter, 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(count_occurrences) + assert "# write your code here" not in lines, ( + "You have to" " remove the unnecessary comment '# write your code here'" + )