Python « Как правильно написать doc тест для функции?

Первый раз нужно написать doc-тест для небольшой функции. Исходя из найденного на просторах Интернета, делаю следующее:

1. Пишу код функции и сохраняю в файл с именем func_name.py
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .python.geshi_code {font-family:monospace;} .python.geshi_code .imp {font-weight: bold; color: red;} .python.geshi_code .kw1 {color: #ff7700;font-weight:bold;} .python.geshi_code .kw2 {color: #008000;} .python.geshi_code .kw3 {color: #dc143c;} .python.geshi_code .kw4 {color: #0000cd;} .python.geshi_code .co1 {color: #808080; font-style: italic;} .python.geshi_code .coMULTI {color: #808080; font-style: italic;} .python.geshi_code .es0 {color: #000099; font-weight: bold;} .python.geshi_code .br0 {color: black;} .python.geshi_code .sy0 {color: #66cc66;} .python.geshi_code .st0 {color: #483d8b;} .python.geshi_code .nu0 {color: #ff4500;} .python.geshi_code .me1 {color: black;} .python.geshi_code span.xtra { display:block; }
def func_name(argument):
    #Some code
    return result


2. Пишу тест в текстовый файл func_name_test.txt:

/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .python.geshi_code {font-family:monospace;} .python.geshi_code .imp {font-weight: bold; color: red;} .python.geshi_code .kw1 {color: #ff7700;font-weight:bold;} .python.geshi_code .kw2 {color: #008000;} .python.geshi_code .kw3 {color: #dc143c;} .python.geshi_code .kw4 {color: #0000cd;} .python.geshi_code .co1 {color: #808080; font-style: italic;} .python.geshi_code .coMULTI {color: #808080; font-style: italic;} .python.geshi_code .es0 {color: #000099; font-weight: bold;} .python.geshi_code .br0 {color: black;} .python.geshi_code .sy0 {color: #66cc66;} .python.geshi_code .st0 {color: #483d8b;} .python.geshi_code .nu0 {color: #ff4500;} .python.geshi_code .me1 {color: black;} .python.geshi_code span.xtra { display:block; }
>>> import ~func_name.py
>>> func_name(test_argument)
test_result

3. Запускаю командой /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .bash.geshi_code {font-family:monospace;} .bash.geshi_code .imp {font-weight: bold; color: red;} .bash.geshi_code .kw1 {color: #000000; font-weight: bold;} .bash.geshi_code .kw2 {color: #c20cb9; font-weight: bold;} .bash.geshi_code .kw3 {color: #7a0874; font-weight: bold;} .bash.geshi_code .co0 {color: #666666; font-style: italic;} .bash.geshi_code .co1 {color: #800000;} .bash.geshi_code .co2 {color: #cc0000; font-style: italic;} .bash.geshi_code .co3 {color: #000000; font-weight: bold;} .bash.geshi_code .es1 {color: #000099; font-weight: bold;} .bash.geshi_code .es2 {color: #007800;} .bash.geshi_code .es3 {color: #007800;} .bash.geshi_code .es4 {color: #007800;} .bash.geshi_code .es5 {color: #780078;} .bash.geshi_code .es_h {color: #000099; font-weight: bold;} .bash.geshi_code .br0 {color: #7a0874; font-weight: bold;} .bash.geshi_code .sy0 {color: #000000; font-weight: bold;} .bash.geshi_code .st0 {color: #ff0000;} .bash.geshi_code .st_h {color: #ff0000;} .bash.geshi_code .nu0 {color: #000000;} .bash.geshi_code .re0 {color: #007800;} .bash.geshi_code .re1 {color: #007800;} .bash.geshi_code .re2 {color: #007800;} .bash.geshi_code .re4 {color: #007800;} .bash.geshi_code .re5 {color: #660033;} .bash.geshi_code span.xtra { display:block; }
python -m doctest func_name_test.txt


В терминале выскакивает ошибка /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .bash.geshi_code {font-family:monospace;} .bash.geshi_code .imp {font-weight: bold; color: red;} .bash.geshi_code .kw1 {color: #000000; font-weight: bold;} .bash.geshi_code .kw2 {color: #c20cb9; font-weight: bold;} .bash.geshi_code .kw3 {color: #7a0874; font-weight: bold;} .bash.geshi_code .co0 {color: #666666; font-style: italic;} .bash.geshi_code .co1 {color: #800000;} .bash.geshi_code .co2 {color: #cc0000; font-style: italic;} .bash.geshi_code .co3 {color: #000000; font-weight: bold;} .bash.geshi_code .es1 {color: #000099; font-weight: bold;} .bash.geshi_code .es2 {color: #007800;} .bash.geshi_code .es3 {color: #007800;} .bash.geshi_code .es4 {color: #007800;} .bash.geshi_code .es5 {color: #780078;} .bash.geshi_code .es_h {color: #000099; font-weight: bold;} .bash.geshi_code .br0 {color: #7a0874; font-weight: bold;} .bash.geshi_code .sy0 {color: #000000; font-weight: bold;} .bash.geshi_code .st0 {color: #ff0000;} .bash.geshi_code .st_h {color: #ff0000;} .bash.geshi_code .nu0 {color: #000000;} .bash.geshi_code .re0 {color: #007800;} .bash.geshi_code .re1 {color: #007800;} .bash.geshi_code .re2 {color: #007800;} .bash.geshi_code .re4 {color: #007800;} .bash.geshi_code .re5 {color: #660033;} .bash.geshi_code span.xtra { display:block; }
name 'func_name'
is not defined

Пробовал /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .python.geshi_code {font-family:monospace;} .python.geshi_code .imp {font-weight: bold; color: red;} .python.geshi_code .kw1 {color: #ff7700;font-weight:bold;} .python.geshi_code .kw2 {color: #008000;} .python.geshi_code .kw3 {color: #dc143c;} .python.geshi_code .kw4 {color: #0000cd;} .python.geshi_code .co1 {color: #808080; font-style: italic;} .python.geshi_code .coMULTI {color: #808080; font-style: italic;} .python.geshi_code .es0 {color: #000099; font-weight: bold;} .python.geshi_code .br0 {color: black;} .python.geshi_code .sy0 {color: #66cc66;} .python.geshi_code .st0 {color: #483d8b;} .python.geshi_code .nu0 {color: #ff4500;} .python.geshi_code .me1 {color: black;} .python.geshi_code span.xtra { display:block; }
from file_name import *
, /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .python.geshi_code {font-family:monospace;} .python.geshi_code .imp {font-weight: bold; color: red;} .python.geshi_code .kw1 {color: #ff7700;font-weight:bold;} .python.geshi_code .kw2 {color: #008000;} .python.geshi_code .kw3 {color: #dc143c;} .python.geshi_code .kw4 {color: #0000cd;} .python.geshi_code .co1 {color: #808080; font-style: italic;} .python.geshi_code .coMULTI {color: #808080; font-style: italic;} .python.geshi_code .es0 {color: #000099; font-weight: bold;} .python.geshi_code .br0 {color: black;} .python.geshi_code .sy0 {color: #66cc66;} .python.geshi_code .st0 {color: #483d8b;} .python.geshi_code .nu0 {color: #ff4500;} .python.geshi_code .me1 {color: black;} .python.geshi_code span.xtra { display:block; }
from file_name import func_name
- тот же результат.

Что не так?

1 ответов