src/pyams_pagelet/tests/test_utilsdocs.py
changeset 12 fc3542685741
parent 0 44692d47182f
--- a/src/pyams_pagelet/tests/test_utilsdocs.py	Mon Jun 11 17:30:43 2018 +0200
+++ b/src/pyams_pagelet/tests/test_utilsdocs.py	Wed Nov 27 19:37:28 2019 +0100
@@ -14,18 +14,20 @@
 Generic Test case for pyams_pagelet doctest
 """
 
+import doctest
+import os
+import unittest
+
+from pyams_pagelet.tests import get_package_dir
+
+
 __docformat__ = 'restructuredtext'
 
-import unittest
-import doctest
-import sys
-import os
+CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
 
 
-current_dir = os.path.dirname(__file__)
-
-def doc_suite(test_dir, setUp=None, tearDown=None, globs=None):
-    """Returns a test suite, based on doctests found in /doctest."""
+def doc_suite(test_dir, setUp=None, tearDown=None, globs=None):  # pylint: disable=invalid-name
+    """Returns a test suite, based on doctests found in /doctests"""
     suite = []
     if globs is None:
         globs = globals()
@@ -33,15 +35,12 @@
     flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
              doctest.REPORT_ONLY_FIRST_FAILURE)
 
-    package_dir = os.path.split(test_dir)[0]
-    if package_dir not in sys.path:
-        sys.path.append(package_dir)
-
+    package_dir = get_package_dir(test_dir)
     doctest_dir = os.path.join(package_dir, 'doctests')
 
     # filtering files on extension
     docs = [os.path.join(doctest_dir, doc) for doc in
-            os.listdir(doctest_dir) if doc.endswith('.txt')]
+            os.listdir(doctest_dir) if doc.endswith('.txt') or doc.endswith('.rst')]
 
     for test in docs:
         suite.append(doctest.DocFileSuite(test, optionflags=flags,
@@ -51,10 +50,11 @@
 
     return unittest.TestSuite(suite)
 
+
 def test_suite():
     """returns the test suite"""
-    return doc_suite(current_dir)
+    return doc_suite(CURRENT_DIR)
+
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
-