summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-25 14:01:57 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-25 14:01:57 +0000
commitddf5175e10ca55e8baafd2d402918a9d7d51451d (patch)
treef341068b88f70ac84ac8ed1ed89e78114f23b2d6 /docutils
parentc6ade6048d93724358a80100196971f6583fa64d (diff)
downloaddocutils-ddf5175e10ca55e8baafd2d402918a9d7d51451d.tar.gz
Fix import errors with ``python -m unittest``.
Running standard unittest on the test suite resulted in 89 ImportErrors because ``import DocutilsTestSupport was used to set up sys.path() but the module could not be found on the original sys.path(). git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9274 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/test/DocutilsTestSupport.py13
-rw-r--r--docutils/test/__init__.py1
-rwxr-xr-xdocutils/test/alltests.py25
-rw-r--r--docutils/test/conftest.py17
-rw-r--r--docutils/test/test__init__.py8
-rw-r--r--docutils/test/test_error_reporting.py6
-rwxr-xr-xdocutils/test/test_functional.py6
-rwxr-xr-xdocutils/test/test_io.py6
-rwxr-xr-xdocutils/test/test_language.py5
-rwxr-xr-xdocutils/test/test_nodes.py7
-rw-r--r--docutils/test/test_parsers/test_get_parser_class.py21
-rw-r--r--docutils/test/test_parsers/test_parser.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_SimpleTableParser.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_TableParser.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_bullet_lists.py7
-rw-r--r--docutils/test/test_parsers/test_rst/test_character_level_inline_markup.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_citations.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_comments.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_definition_lists.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test__init__.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py6
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_class.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code_long.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code_none.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_code_parsing.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_compound.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_container.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_contents.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_date.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_decorations.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_default_role.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_figures.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_images.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_math.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_meta.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_raw.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_replace.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_role.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_rubrics.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_sectnum.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_sidebars.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_tables.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_target_notes.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_test_directives.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_title.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_topics.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_unicode.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_directives/test_unknown.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_doctest_blocks.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_east_asian_text.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_enumerated_lists.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_field_lists.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_footnotes.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_inline_markup.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_interpreted.py7
-rw-r--r--docutils/test/test_parsers/test_rst/test_interpreted_fr.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_line_blocks.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_line_length_limit.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_line_length_limit_default.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_literal_blocks.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_option_lists.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_outdenting.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_paragraphs.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_section_headers.py7
-rw-r--r--docutils/test/test_parsers/test_rst/test_source_line.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_substitutions.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_tables.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_targets.py7
-rwxr-xr-xdocutils/test/test_parsers/test_rst/test_transitions.py7
-rwxr-xr-xdocutils/test/test_pickle.py10
-rwxr-xr-xdocutils/test/test_publisher.py7
-rw-r--r--docutils/test/test_readers/test_get_reader_class.py16
-rwxr-xr-xdocutils/test/test_readers/test_pep/test_inline_markup.py7
-rwxr-xr-xdocutils/test/test_readers/test_pep/test_rfc2822.py7
-rwxr-xr-xdocutils/test/test_settings.py7
-rwxr-xr-xdocutils/test/test_statemachine.py10
-rwxr-xr-xdocutils/test/test_transforms/test___init__.py7
-rwxr-xr-xdocutils/test/test_transforms/test_class.py7
-rwxr-xr-xdocutils/test/test_transforms/test_contents.py7
-rwxr-xr-xdocutils/test/test_transforms/test_docinfo.py7
-rwxr-xr-xdocutils/test/test_transforms/test_expose_internals.py7
-rwxr-xr-xdocutils/test/test_transforms/test_filter.py7
-rw-r--r--docutils/test/test_transforms/test_filter_messages.py7
-rwxr-xr-xdocutils/test/test_transforms/test_footnotes.py7
-rwxr-xr-xdocutils/test/test_transforms/test_hyperlinks.py7
-rw-r--r--docutils/test/test_transforms/test_hyperlinks_de.py7
-rwxr-xr-xdocutils/test/test_transforms/test_messages.py7
-rwxr-xr-xdocutils/test/test_transforms/test_peps.py7
-rwxr-xr-xdocutils/test/test_transforms/test_sectnum.py7
-rw-r--r--docutils/test/test_transforms/test_smartquotes.py7
-rwxr-xr-xdocutils/test/test_transforms/test_strip_comments.py7
-rw-r--r--docutils/test/test_transforms/test_strip_elements_with_class.py7
-rw-r--r--docutils/test/test_transforms/test_substitution_expansion_length_limit.py7
-rwxr-xr-xdocutils/test/test_transforms/test_substitutions.py7
-rwxr-xr-xdocutils/test/test_transforms/test_target_notes.py7
-rwxr-xr-xdocutils/test/test_transforms/test_transitions.py7
-rwxr-xr-xdocutils/test/test_transforms/test_writer_aux.py7
-rwxr-xr-xdocutils/test/test_traversals.py7
-rwxr-xr-xdocutils/test/test_viewlist.py7
-rw-r--r--docutils/test/test_writers/test_get_writer_class.py16
-rwxr-xr-xdocutils/test/test_writers/test_html4css1_parts.py7
-rw-r--r--docutils/test/test_writers/test_html5_polyglot_misc.py7
-rw-r--r--docutils/test/test_writers/test_html5_polyglot_parts.py7
-rw-r--r--docutils/test/test_writers/test_html5_template.py7
-rw-r--r--docutils/test/test_writers/test_manpage.py7
-rwxr-xr-xdocutils/test/test_writers/test_null.py7
-rwxr-xr-xdocutils/test/test_writers/test_odt.py13
-rwxr-xr-xdocutils/test/test_writers/test_pseudoxml.py7
-rwxr-xr-xdocutils/test/test_writers/test_s5.py7
114 files changed, 715 insertions, 150 deletions
diff --git a/docutils/test/DocutilsTestSupport.py b/docutils/test/DocutilsTestSupport.py
deleted file mode 100644
index db901469a..000000000
--- a/docutils/test/DocutilsTestSupport.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# $Id$
-# Authors: David Goodger <goodger@python.org>;
-# Garth Kidd <garth@deadlybloodyserious.com>
-# Copyright: This module has been placed in the public domain.
-
-__docformat__ = 'reStructuredText'
-
-import os
-import sys
-
-testroot = os.path.abspath(os.path.dirname(__file__))
-sys.path.insert(0, os.path.dirname(testroot))
-sys.path.insert(0, testroot)
diff --git a/docutils/test/__init__.py b/docutils/test/__init__.py
index e69de29bb..771be5980 100644
--- a/docutils/test/__init__.py
+++ b/docutils/test/__init__.py
@@ -0,0 +1 @@
+"""The Docutils unit test suite."""
diff --git a/docutils/test/alltests.py b/docutils/test/alltests.py
index 7346416de..9f4fb0e82 100755
--- a/docutils/test/alltests.py
+++ b/docutils/test/alltests.py
@@ -17,25 +17,20 @@ import time
# and setup outside of unittest.
start = time.time()
-import sys # noqa: E402
import atexit # noqa: E402
import glob # noqa: E402
+import importlib # noqa: E402
import os # noqa: E402
+from pathlib import Path # noqa: E402
import platform # noqa: E402
-import warnings # noqa: E402
-from importlib import import_module # noqa: E402
-import DocutilsTestSupport # noqa: E402,F401 must be imported before docutils
-import docutils # noqa: E402
+import sys # noqa: E402
-warnings.filterwarnings('ignore',
- message='.*return type of publish_string.*',
- category=FutureWarning)
-warnings.filterwarnings('ignore',
- message=r".*StringOutput.encode\(\)'s return type.*",
- category=FutureWarning)
+# prepend the "docutils root" to the Python library path
+# so we import the local `docutils` package.
+DOCUTILS_ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(DOCUTILS_ROOT))
-# TEST_ROOT is ./test/ from the docutils root
-TEST_ROOT = os.path.abspath(os.path.dirname(__file__))
+import docutils # noqa: E402
class Tee:
@@ -98,7 +93,7 @@ def loadTestModules(path):
sys.path.insert(0, path)
for mod in testModules:
try:
- module = import_module(mod)
+ module = importlib.import_module(mod)
except ImportError:
print(f"ERROR: Can't import {mod}, skipping its tests:",
file=sys.stderr)
@@ -138,7 +133,7 @@ class NumbersTestResult(unittest.TextTestResult):
if __name__ == '__main__':
- suite = loadTestModules(TEST_ROOT)
+ suite = loadTestModules(DOCUTILS_ROOT/'test')
print(f'Testing Docutils {docutils.__version__} '
f'with Python {sys.version.split()[0]} '
f'on {time.strftime("%Y-%m-%d at %H:%M:%S")}')
diff --git a/docutils/test/conftest.py b/docutils/test/conftest.py
index bd0ef995a..39b1dc3e4 100644
--- a/docutils/test/conftest.py
+++ b/docutils/test/conftest.py
@@ -1,21 +1,28 @@
def pytest_report_header(config):
import os
+ import pathlib
import platform
import sys
import time
- # DocutilsTestSupport must be imported before docutils
- from . import DocutilsTestSupport # NoQA: F401
- import docutils
+ # get metadata of the local `docutils` package
+ docutils_root = pathlib.Path(__file__).parents[1] / 'docutils'
+ namespace = {}
+ exec((docutils_root/'__init__.py').read_text(encoding='utf-8'), namespace)
return '\n'.join((
'',
- f'Testing Docutils {docutils.__version__} '
+ f'Testing Docutils {namespace["__version__"]} '
f'with Python {sys.version.split()[0]} '
f'on {time.strftime("%Y-%m-%d at %H:%M:%S")}',
f'OS: {platform.system()} {platform.release()} {platform.version()} '
f'({sys.platform}, {platform.platform()})',
f'Working directory: {os.getcwd()}',
- f'Docutils package: {os.path.dirname(docutils.__file__)}',
+ f'Docutils package: {docutils_root}',
'',
))
+
+
+# self-test
+if __name__ == '__main__':
+ print(pytest_report_header(None))
diff --git a/docutils/test/test__init__.py b/docutils/test/test__init__.py
index 084e1a5f6..8dda7b36f 100644
--- a/docutils/test/test__init__.py
+++ b/docutils/test/test__init__.py
@@ -8,7 +8,15 @@
Test module for the docutils' __init__.py.
"""
+from pathlib import Path
+import sys
import unittest
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
import docutils
import docutils.utils
from docutils import VersionInfo
diff --git a/docutils/test/test_error_reporting.py b/docutils/test/test_error_reporting.py
index 9334349b3..dc35d6514 100644
--- a/docutils/test/test_error_reporting.py
+++ b/docutils/test/test_error_reporting.py
@@ -25,11 +25,15 @@ unless the minimal required Python version has this problem fixed.
"""
from io import StringIO, BytesIO
+from pathlib import Path
import sys
import unittest
import warnings
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
from docutils import frontend, utils
import docutils.parsers.rst
diff --git a/docutils/test/test_functional.py b/docutils/test/test_functional.py
index 17a81bb50..d1a1d5f17 100755
--- a/docutils/test/test_functional.py
+++ b/docutils/test/test_functional.py
@@ -13,8 +13,14 @@ __ ../../docs/dev/testing.html#functional
from pathlib import Path
import shutil
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import core, SettingsSpec
FUNCTIONAL = Path('functional')
diff --git a/docutils/test/test_io.py b/docutils/test/test_io.py
index 4055d85c9..33c712099 100755
--- a/docutils/test/test_io.py
+++ b/docutils/test/test_io.py
@@ -10,9 +10,15 @@ Test module for io.py.
import os.path
from io import StringIO, BytesIO
+from pathlib import Path
import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import io
# DATA_ROOT is ./test/data/ from the docutils root
diff --git a/docutils/test/test_language.py b/docutils/test/test_language.py
index 6e7f2298d..9e438ee40 100755
--- a/docutils/test/test_language.py
+++ b/docutils/test/test_language.py
@@ -21,7 +21,8 @@ import unittest
if __name__ == '__main__':
# prepend the "docutils root" to the Python library path
# so we import the local `docutils` package.
- sys.path.insert(0, str(Path(__file__).parent))
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import frontend, languages, utils
from docutils.parsers.rst import languages as rst_languages
@@ -52,7 +53,7 @@ def get_languages():
# requires local_dummy_lang.py in test directory (testroot)
# The local_dummy_lang.py contains all the fields from both
# the docutils language tags and the parser.rst language tags
- language_list += ['local_dummy_lang']
+ language_list += ['test.local_dummy_lang']
return language_list
diff --git a/docutils/test/test_nodes.py b/docutils/test/test_nodes.py
index e745c43ff..48d350bb7 100755
--- a/docutils/test/test_nodes.py
+++ b/docutils/test/test_nodes.py
@@ -7,8 +7,15 @@
Test module for nodes.py.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import nodes, utils
debug = False
diff --git a/docutils/test/test_parsers/test_get_parser_class.py b/docutils/test/test_parsers/test_get_parser_class.py
index 22264e658..90fb13496 100644
--- a/docutils/test/test_parsers/test_get_parser_class.py
+++ b/docutils/test/test_parsers/test_get_parser_class.py
@@ -11,15 +11,16 @@ from pathlib import Path
import sys
import unittest
-if __name__ == '__main__':
- # prepend the "docutils root" to the Python library path
- # so we import the local `docutils` package.
- sys.path.insert(0, str(Path(__file__).parents[2]))
- # prepend the "test root", home of the `local_parser`
- sys.path.insert(0, str(Path(__file__).parents[2]/'test'))
-
-from docutils.core import publish_string
-from docutils.parsers import get_parser_class
+# Prepend the "docutils root" to the Python library path
+# so we import the local `docutils` and `test` packages.
+# ensure `test` package can be loaded also if not running as __main__
+# (required by ``python -m unittest``
+DOCUTILS_ROOT = Path(__file__).parents[2]
+if str(DOCUTILS_ROOT) not in sys.path:
+ sys.path.insert(0, str(DOCUTILS_ROOT))
+
+from docutils.core import publish_string # noqa: E402
+from docutils.parsers import get_parser_class # noqa: E402
try:
md_parser_class = get_parser_class('recommonmark')
except ImportError:
@@ -38,7 +39,7 @@ class GetParserClassTestCase(unittest.TestCase):
def test_local_parser(self):
# requires local-parser.py in "test root" directory
- get_parser_class('local-parser')
+ get_parser_class('test.local-parser')
# raises ImportError on failure
diff --git a/docutils/test/test_parsers/test_parser.py b/docutils/test/test_parsers/test_parser.py
index 7d76eaf49..317f5d28b 100644
--- a/docutils/test/test_parsers/test_parser.py
+++ b/docutils/test/test_parsers/test_parser.py
@@ -7,8 +7,15 @@
Tests for basic functionality of parser classes.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
+
from docutils import parsers, utils, frontend
diff --git a/docutils/test/test_parsers/test_rst/test_SimpleTableParser.py b/docutils/test/test_parsers/test_rst/test_SimpleTableParser.py
index b7fa21e84..358439a0f 100755
--- a/docutils/test/test_parsers/test_rst/test_SimpleTableParser.py
+++ b/docutils/test/test_parsers/test_rst/test_SimpleTableParser.py
@@ -7,9 +7,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.parsers.rst import tableparser
from docutils.statemachine import StringList, string2lines
diff --git a/docutils/test/test_parsers/test_rst/test_TableParser.py b/docutils/test/test_parsers/test_rst/test_TableParser.py
index b604f7a14..09e66102a 100755
--- a/docutils/test/test_parsers/test_rst/test_TableParser.py
+++ b/docutils/test/test_parsers/test_rst/test_TableParser.py
@@ -7,9 +7,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.parsers.rst import tableparser
from docutils.statemachine import StringList, string2lines
diff --git a/docutils/test/test_parsers/test_rst/test_bullet_lists.py b/docutils/test/test_parsers/test_rst/test_bullet_lists.py
index a4c56bc8c..cc7fc5fb1 100755
--- a/docutils/test/test_parsers/test_rst/test_bullet_lists.py
+++ b/docutils/test/test_parsers/test_rst/test_bullet_lists.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_character_level_inline_markup.py b/docutils/test/test_parsers/test_rst/test_character_level_inline_markup.py
index 3fcd501a9..a031878ee 100644
--- a/docutils/test/test_parsers/test_rst/test_character_level_inline_markup.py
+++ b/docutils/test/test_parsers/test_rst/test_character_level_inline_markup.py
@@ -10,9 +10,14 @@ with the "character-level-inline-markup" setting.
Experimental.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_citations.py b/docutils/test/test_parsers/test_rst/test_citations.py
index 21a50fd3d..9e62fe96a 100755
--- a/docutils/test/test_parsers/test_rst/test_citations.py
+++ b/docutils/test/test_parsers/test_rst/test_citations.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_comments.py b/docutils/test/test_parsers/test_rst/test_comments.py
index c1bc77605..a91359027 100755
--- a/docutils/test/test_parsers/test_rst/test_comments.py
+++ b/docutils/test/test_parsers/test_rst/test_comments.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_definition_lists.py b/docutils/test/test_parsers/test_rst/test_definition_lists.py
index 010467c6e..49c2b2331 100755
--- a/docutils/test/test_parsers/test_rst/test_definition_lists.py
+++ b/docutils/test/test_parsers/test_rst/test_definition_lists.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test__init__.py b/docutils/test/test_parsers/test_rst/test_directives/test__init__.py
index d0bd8d8c0..275a04170 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test__init__.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test__init__.py
@@ -13,8 +13,15 @@
Test module for `docutils.parsers.rst.directives`.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
+
import docutils
import docutils.parsers.null
from docutils.parsers.rst import directives
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py
index fadbb9d55..baf0f35fc 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_admonitions_dummy_lang.py
@@ -16,8 +16,6 @@ if __name__ == '__main__':
# prepend the "docutils root" to the Python library path
# so we import the local `docutils` package.
sys.path.insert(0, str(Path(__file__).parents[4]))
- # also prepend the "test root", for import of ``local_dummy_lang.py``
- sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
@@ -32,7 +30,7 @@ class ParserTestCase(unittest.TestCase):
parser = Parser()
settings = get_default_settings(Parser)
settings.warning_stream = ''
- settings.language_code = 'local-dummy-lang'
+ settings.language_code = 'test.local-dummy-lang'
for name, cases in totest.items():
for casenum, (case_input, case_expected) in enumerate(cases):
with self.subTest(id=f'totest[{name!r}][{casenum}]'):
@@ -57,7 +55,7 @@ totest['admonitions'] = [
directive with silly localised name.
<system_message level="1" line="3" source="test data" type="INFO">
<paragraph>
- No directive entry for "Attention" in module "local_dummy_lang".
+ No directive entry for "Attention" in module "test.local_dummy_lang".
Using English fallback for directive "Attention".
<attention>
<paragraph>
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py b/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py
index 38e69c5f8..08a12f315 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_block_quotes.py
@@ -9,9 +9,14 @@ Tests for the block quote directives "epigraph", "highlights", and
"pull-quote".
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_class.py b/docutils/test/test_parsers/test_rst/test_directives/test_class.py
index de62eeed2..d21dc81bf 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_class.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_class.py
@@ -8,9 +8,14 @@
Tests for the 'class' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code.py b/docutils/test/test_parsers/test_rst/test_directives/test_code.py
index 8cdb57ee9..289258f3f 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code.py
@@ -8,9 +8,14 @@
Test the 'code' directive in parsers/rst/directives/body.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
index 461ed23b2..3b966f0ea 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
@@ -8,9 +8,14 @@
Test the 'code' directive in body.py with syntax_highlight = 'long'.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py
index fc27048d6..cb8cfd2d9 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py
@@ -8,9 +8,14 @@
Test the 'code' directive in body.py with syntax_highlight = 'none'.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_parsing.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_parsing.py
index 1dabd4c91..f7cdf2162 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_code_parsing.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_parsing.py
@@ -13,8 +13,15 @@
Various tests for the `pygments` code highlighter.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
+
from docutils.core import publish_string
from docutils.utils.code_analyzer import with_pygments
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_compound.py b/docutils/test/test_parsers/test_rst/test_directives/test_compound.py
index 67a3ccde8..850753218 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_compound.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_compound.py
@@ -8,9 +8,14 @@
Tests for the 'compound' directive from body.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_container.py b/docutils/test/test_parsers/test_rst/test_directives/test_container.py
index 448a42404..e125035f3 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_container.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_container.py
@@ -8,9 +8,14 @@
Tests for the 'container' directive from body.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_contents.py b/docutils/test/test_parsers/test_rst/test_directives/test_contents.py
index 08903c0d1..eada86c26 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_contents.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_contents.py
@@ -8,9 +8,14 @@
Tests for parts.py contents directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_date.py b/docutils/test/test_parsers/test_rst/test_directives/test_date.py
index 81f7fb351..97e0573bd 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_date.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_date.py
@@ -9,9 +9,14 @@ Tests for the misc.py "date" directive.
"""
import time
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.io import _locale_encoding # noqa
from docutils.frontend import get_default_settings
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py b/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py
index 9bde1c61c..3ef3c3407 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_decorations.py
@@ -8,9 +8,14 @@
Tests for the "header" & "footer" directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py b/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py
index 2fbca8e7c..0d16531ac 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_default_role.py
@@ -8,9 +8,14 @@
Tests for misc.py "default-role" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_figures.py b/docutils/test/test_parsers/test_rst/test_directives/test_figures.py
index 09405579a..f1f83a4c8 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_figures.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_figures.py
@@ -8,9 +8,14 @@
Tests for images.py figure directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_images.py b/docutils/test/test_parsers/test_rst/test_directives/test_images.py
index 3ef8e8286..f0fa3b030 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_images.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_images.py
@@ -8,9 +8,14 @@
Tests for images.py image directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py b/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py
index 52061b3ad..e94b345e9 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_line_blocks.py
@@ -8,9 +8,14 @@
Tests for the body.py 'line-block' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_math.py b/docutils/test/test_parsers/test_rst/test_directives/test_math.py
index 47138b7ac..3bb5298b2 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_math.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_math.py
@@ -8,9 +8,14 @@
Tests for the 'math' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_meta.py b/docutils/test/test_parsers/test_rst/test_directives/test_meta.py
index 3599163be..d17aece1a 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_meta.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_meta.py
@@ -8,9 +8,14 @@
Tests for html meta directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py b/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py
index daaa00574..f8419c4c5 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_parsed_literals.py
@@ -8,9 +8,14 @@
Tests for the body.py 'parsed-literal' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_raw.py b/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
index af099ae20..d0b459711 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
@@ -9,9 +9,14 @@ Tests for misc.py "raw" directive.
"""
import os.path
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_replace.py b/docutils/test/test_parsers/test_rst/test_directives/test_replace.py
index b9c0b99e9..fcedd73e5 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_replace.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_replace.py
@@ -8,9 +8,14 @@
Tests for misc.py "replace" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py
index b733ad99f..d34493c5d 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_replace_fr.py
@@ -9,9 +9,14 @@ Tests for misc.py "replace" directive.
Test in french (not default/fallback language).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_role.py b/docutils/test/test_parsers/test_rst/test_directives/test_role.py
index c39fee571..129930d86 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_role.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_role.py
@@ -8,9 +8,14 @@
Tests for misc.py "role" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser, roles
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_rubrics.py b/docutils/test/test_parsers/test_rst/test_directives/test_rubrics.py
index 0cff6b4f9..8c0137525 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_rubrics.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_rubrics.py
@@ -8,9 +8,14 @@
Tests for the "rubric" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_sectnum.py b/docutils/test/test_parsers/test_rst/test_directives/test_sectnum.py
index 072243e25..a879b2972 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_sectnum.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_sectnum.py
@@ -8,9 +8,14 @@
Tests for the 'sectnum' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py b/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py
index 41a6994f6..89f15a483 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py
@@ -8,9 +8,14 @@
Tests for the "sidebar" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_tables.py b/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
index 79befac9e..12ef481b8 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
@@ -11,9 +11,14 @@ Tests for tables.py directives.
import os
import csv
import platform
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py b/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py
index 5228c88bb..dd5a84c20 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_target_notes.py
@@ -8,9 +8,14 @@
Tests for the target-notes directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py b/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py
index 3c908bd7d..919b7f468 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_test_directives.py
@@ -8,9 +8,14 @@
Tests for misc.py test directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_title.py b/docutils/test/test_parsers/test_rst/test_directives/test_title.py
index d758956d4..b807a7a92 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_title.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_title.py
@@ -8,9 +8,14 @@
Tests for the 'title' directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_topics.py b/docutils/test/test_parsers/test_rst/test_directives/test_topics.py
index ab7533f82..02ab530f7 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_topics.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_topics.py
@@ -8,9 +8,14 @@
Tests for the "topic" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py b/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py
index 7f1796c77..4134858da 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_unicode.py
@@ -9,9 +9,14 @@ Tests for misc.py "unicode" directive.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_unknown.py b/docutils/test/test_parsers/test_rst/test_directives/test_unknown.py
index 4fa86da40..5ddabe87a 100755
--- a/docutils/test/test_parsers/test_rst/test_directives/test_unknown.py
+++ b/docutils/test/test_parsers/test_rst/test_directives/test_unknown.py
@@ -8,9 +8,14 @@
Tests for unknown directives.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[4]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_doctest_blocks.py b/docutils/test/test_parsers/test_rst/test_doctest_blocks.py
index 3304d3545..da188f823 100755
--- a/docutils/test/test_parsers/test_rst/test_doctest_blocks.py
+++ b/docutils/test/test_parsers/test_rst/test_doctest_blocks.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_east_asian_text.py b/docutils/test/test_parsers/test_rst/test_east_asian_text.py
index a0ee9a34e..f6434102c 100755
--- a/docutils/test/test_parsers/test_rst/test_east_asian_text.py
+++ b/docutils/test/test_parsers/test_rst/test_east_asian_text.py
@@ -7,9 +7,14 @@
Tests for East Asian text with double-width characters.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_enumerated_lists.py b/docutils/test/test_parsers/test_rst/test_enumerated_lists.py
index 74fe6e2c6..76d127c5d 100755
--- a/docutils/test/test_parsers/test_rst/test_enumerated_lists.py
+++ b/docutils/test/test_parsers/test_rst/test_enumerated_lists.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_field_lists.py b/docutils/test/test_parsers/test_rst/test_field_lists.py
index b6a31c7e6..b5b78df46 100755
--- a/docutils/test/test_parsers/test_rst/test_field_lists.py
+++ b/docutils/test/test_parsers/test_rst/test_field_lists.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_footnotes.py b/docutils/test/test_parsers/test_rst/test_footnotes.py
index b96a1cdac..e51fdd735 100755
--- a/docutils/test/test_parsers/test_rst/test_footnotes.py
+++ b/docutils/test/test_parsers/test_rst/test_footnotes.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_inline_markup.py b/docutils/test/test_parsers/test_rst/test_inline_markup.py
index 849afadfe..9bf6d4ef7 100755
--- a/docutils/test/test_parsers/test_rst/test_inline_markup.py
+++ b/docutils/test/test_parsers/test_rst/test_inline_markup.py
@@ -8,9 +8,14 @@ Tests for inline markup in docutils/parsers/rst/states.py.
Interpreted text tests are in a separate module, test_interpreted.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_interpreted.py b/docutils/test/test_parsers/test_rst/test_interpreted.py
index cad3322d9..13359031b 100755
--- a/docutils/test/test_parsers/test_rst/test_interpreted.py
+++ b/docutils/test/test_parsers/test_rst/test_interpreted.py
@@ -8,9 +8,14 @@
Tests for interpreted text in docutils/parsers/rst/states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_interpreted_fr.py b/docutils/test/test_parsers/test_rst/test_interpreted_fr.py
index a24d7e4c3..8418881ca 100644
--- a/docutils/test/test_parsers/test_rst/test_interpreted_fr.py
+++ b/docutils/test/test_parsers/test_rst/test_interpreted_fr.py
@@ -9,9 +9,14 @@ Tests for interpreted text in docutils/parsers/rst/states.py.
Test not default/fallback language french.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser, roles
diff --git a/docutils/test/test_parsers/test_rst/test_line_blocks.py b/docutils/test/test_parsers/test_rst/test_line_blocks.py
index 9e8022684..52ebcd512 100755
--- a/docutils/test/test_parsers/test_rst/test_line_blocks.py
+++ b/docutils/test/test_parsers/test_rst/test_line_blocks.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_line_length_limit.py b/docutils/test/test_parsers/test_rst/test_line_length_limit.py
index 9d546d403..c2adcae82 100755
--- a/docutils/test/test_parsers/test_rst/test_line_length_limit.py
+++ b/docutils/test/test_parsers/test_rst/test_line_length_limit.py
@@ -15,9 +15,14 @@ Interpreted text tests are in a separate module, test_interpreted.py.
"""
import os.path
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py b/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py
index fc102a028..8f828213d 100755
--- a/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py
+++ b/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py
@@ -14,9 +14,14 @@ Tests for inline markup in docutils/parsers/rst/states.py.
Interpreted text tests are in a separate module, test_interpreted.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_literal_blocks.py b/docutils/test/test_parsers/test_rst/test_literal_blocks.py
index 376978d9a..ce3e3b75e 100755
--- a/docutils/test/test_parsers/test_rst/test_literal_blocks.py
+++ b/docutils/test/test_parsers/test_rst/test_literal_blocks.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_option_lists.py b/docutils/test/test_parsers/test_rst/test_option_lists.py
index bedd0416d..a8df8ab7a 100755
--- a/docutils/test/test_parsers/test_rst/test_option_lists.py
+++ b/docutils/test/test_parsers/test_rst/test_option_lists.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_outdenting.py b/docutils/test/test_parsers/test_rst/test_outdenting.py
index 7880f950c..ad05c4e78 100755
--- a/docutils/test/test_parsers/test_rst/test_outdenting.py
+++ b/docutils/test/test_parsers/test_rst/test_outdenting.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_paragraphs.py b/docutils/test/test_parsers/test_rst/test_paragraphs.py
index aef287c88..ddba8186c 100755
--- a/docutils/test/test_parsers/test_rst/test_paragraphs.py
+++ b/docutils/test/test_parsers/test_rst/test_paragraphs.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_section_headers.py b/docutils/test/test_parsers/test_rst/test_section_headers.py
index 1c93c8593..e2d2c77bd 100755
--- a/docutils/test/test_parsers/test_rst/test_section_headers.py
+++ b/docutils/test/test_parsers/test_rst/test_section_headers.py
@@ -7,9 +7,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_source_line.py b/docutils/test/test_parsers/test_rst/test_source_line.py
index 0d0e2f656..9b0fc59a0 100644
--- a/docutils/test/test_parsers/test_rst/test_source_line.py
+++ b/docutils/test/test_parsers/test_rst/test_source_line.py
@@ -24,9 +24,14 @@ adding them to more nodes is regarded a compatible feature extension.
# to make internal attributes visible.
import os
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_substitutions.py b/docutils/test/test_parsers/test_rst/test_substitutions.py
index fe0fb98d9..d562f3ab3 100755
--- a/docutils/test/test_parsers/test_rst/test_substitutions.py
+++ b/docutils/test/test_parsers/test_rst/test_substitutions.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_tables.py b/docutils/test/test_parsers/test_rst/test_tables.py
index 76746e1bc..a7d8c3c8b 100755
--- a/docutils/test/test_parsers/test_rst/test_tables.py
+++ b/docutils/test/test_parsers/test_rst/test_tables.py
@@ -10,9 +10,14 @@ Tests for states.py.
import os
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_targets.py b/docutils/test/test_parsers/test_rst/test_targets.py
index b96f9eeba..f4e97e585 100755
--- a/docutils/test/test_parsers/test_rst/test_targets.py
+++ b/docutils/test/test_parsers/test_rst/test_targets.py
@@ -8,9 +8,14 @@
Tests for states.py.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_parsers/test_rst/test_transitions.py b/docutils/test/test_parsers/test_rst/test_transitions.py
index 8ec4cea64..af630f202 100755
--- a/docutils/test/test_parsers/test_rst/test_transitions.py
+++ b/docutils/test/test_parsers/test_rst/test_transitions.py
@@ -8,9 +8,14 @@
Tests for transition markers.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_pickle.py b/docutils/test/test_pickle.py
index cba3b23dc..c92cb76f1 100755
--- a/docutils/test/test_pickle.py
+++ b/docutils/test/test_pickle.py
@@ -7,8 +7,16 @@
Tests of document tree pickling.
"""
-import unittest
+from pathlib import Path
import pickle
+import sys
+import unittest
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import core
diff --git a/docutils/test/test_publisher.py b/docutils/test/test_publisher.py
index 5aaca88ce..f781809c5 100755
--- a/docutils/test/test_publisher.py
+++ b/docutils/test/test_publisher.py
@@ -9,8 +9,15 @@ Test the `Publisher` facade and the ``publish_*`` convenience functions.
"""
import os.path
import pickle
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
import docutils
from docutils import core, nodes, io
diff --git a/docutils/test/test_readers/test_get_reader_class.py b/docutils/test/test_readers/test_get_reader_class.py
index 6f7ce42ab..3e5620374 100644
--- a/docutils/test/test_readers/test_get_reader_class.py
+++ b/docutils/test/test_readers/test_get_reader_class.py
@@ -9,9 +9,19 @@
test get_reader_class
"""
+from pathlib import Path
+import sys
import unittest
-from docutils.readers import get_reader_class
+# Prepend the "docutils root" to the Python library path
+# so we import the local `docutils` and `test` packages.
+# ensure `test` package can be loaded also if not running as __main__
+# (required by ``python -m unittest``
+DOCUTILS_ROOT = Path(__file__).parents[2]
+if str(DOCUTILS_ROOT) not in sys.path:
+ sys.path.insert(0, str(DOCUTILS_ROOT))
+
+from docutils.readers import get_reader_class # noqa: E402
class GetReaderClassTestCase(unittest.TestCase):
@@ -25,8 +35,8 @@ class GetReaderClassTestCase(unittest.TestCase):
get_reader_class('nope')
def test_local_reader(self):
- # requires local-reader.py in test directory (testroot)
- get_reader_class('local-reader')
+ # requires local-reader.py in `test` package
+ get_reader_class('test.local-reader')
# raises ImportError on failure
diff --git a/docutils/test/test_readers/test_pep/test_inline_markup.py b/docutils/test/test_readers/test_pep/test_inline_markup.py
index 4ef67f2aa..2ce0d5ea7 100755
--- a/docutils/test/test_readers/test_pep/test_inline_markup.py
+++ b/docutils/test/test_readers/test_pep/test_inline_markup.py
@@ -8,9 +8,14 @@
Tests for inline markup in PEPs (readers/pep.py).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_readers/test_pep/test_rfc2822.py b/docutils/test/test_readers/test_pep/test_rfc2822.py
index 52aab37ae..0ff043a0b 100755
--- a/docutils/test/test_readers/test_pep/test_rfc2822.py
+++ b/docutils/test/test_readers/test_pep/test_rfc2822.py
@@ -8,9 +8,14 @@
Tests for RFC-2822 headers in PEPs (readers/pep.py).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[3]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py
index a4c4a309c..a63a0dc98 100755
--- a/docutils/test/test_settings.py
+++ b/docutils/test/test_settings.py
@@ -10,8 +10,15 @@ Tests of runtime settings.
import os
import difflib
import warnings
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import frontend, utils
from docutils.writers import pep_html, html5_polyglot
from docutils.parsers import rst
diff --git a/docutils/test/test_statemachine.py b/docutils/test/test_statemachine.py
index 4bc742e68..744936b87 100755
--- a/docutils/test/test_statemachine.py
+++ b/docutils/test/test_statemachine.py
@@ -8,9 +8,15 @@
Test module for statemachine.py.
"""
-import unittest
-import sys
+from pathlib import Path
import re
+import sys
+import unittest
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
from docutils import statemachine
diff --git a/docutils/test/test_transforms/test___init__.py b/docutils/test/test_transforms/test___init__.py
index 61978e6dc..76b3741ac 100755
--- a/docutils/test/test_transforms/test___init__.py
+++ b/docutils/test/test_transforms/test___init__.py
@@ -8,8 +8,15 @@
Test module for transforms/__init__.py.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
+
from docutils import transforms, utils
diff --git a/docutils/test/test_transforms/test_class.py b/docutils/test/test_transforms/test_class.py
index 9289ed287..7def11092 100755
--- a/docutils/test/test_transforms/test_class.py
+++ b/docutils/test/test_transforms/test_class.py
@@ -8,9 +8,14 @@
Tests for `docutils.transforms.misc.ClassAttribute`.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_contents.py b/docutils/test/test_transforms/test_contents.py
index e0da2c66d..9cbcb50b3 100755
--- a/docutils/test/test_transforms/test_contents.py
+++ b/docutils/test/test_transforms/test_contents.py
@@ -9,9 +9,14 @@ Tests for `docutils.transforms.parts.Contents` (via
`docutils.transforms.universal.LastReaderPending`).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_docinfo.py b/docutils/test/test_transforms/test_docinfo.py
index 9df942dec..b450a70c8 100755
--- a/docutils/test/test_transforms/test_docinfo.py
+++ b/docutils/test/test_transforms/test_docinfo.py
@@ -7,9 +7,14 @@
Tests for docutils.transforms.frontmatter.DocInfo.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_expose_internals.py b/docutils/test/test_transforms/test_expose_internals.py
index fe42f2a43..b1b571937 100755
--- a/docutils/test/test_transforms/test_expose_internals.py
+++ b/docutils/test/test_transforms/test_expose_internals.py
@@ -8,9 +8,14 @@
Test module for universal.ExposeInternals transform.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_filter.py b/docutils/test/test_transforms/test_filter.py
index 24a927f1e..3770e1f81 100755
--- a/docutils/test/test_transforms/test_filter.py
+++ b/docutils/test/test_transforms/test_filter.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.components.Filter.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_filter_messages.py b/docutils/test/test_transforms/test_filter_messages.py
index 197348a6e..0842e288d 100644
--- a/docutils/test/test_transforms/test_filter_messages.py
+++ b/docutils/test/test_transforms/test_filter_messages.py
@@ -16,9 +16,14 @@
Tests for docutils.transforms.universal.FilterMessages.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_footnotes.py b/docutils/test/test_transforms/test_footnotes.py
index 7979b19f3..ffc529273 100755
--- a/docutils/test/test_transforms/test_footnotes.py
+++ b/docutils/test/test_transforms/test_footnotes.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.references.Footnotes.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_hyperlinks.py b/docutils/test/test_transforms/test_hyperlinks.py
index 4c9445d1b..1cabeba3e 100755
--- a/docutils/test/test_transforms/test_hyperlinks.py
+++ b/docutils/test/test_transforms/test_hyperlinks.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.references.Hyperlinks.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_hyperlinks_de.py b/docutils/test/test_transforms/test_hyperlinks_de.py
index 7a45bc4ea..88b57999b 100644
--- a/docutils/test/test_transforms/test_hyperlinks_de.py
+++ b/docutils/test/test_transforms/test_hyperlinks_de.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.references.Hyperlinks with non-English language.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.languages import de, get_language
diff --git a/docutils/test/test_transforms/test_messages.py b/docutils/test/test_transforms/test_messages.py
index 1c18811e1..5ea226171 100755
--- a/docutils/test/test_transforms/test_messages.py
+++ b/docutils/test/test_transforms/test_messages.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.universal.Messages.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_peps.py b/docutils/test/test_transforms/test_peps.py
index 93c02708d..b9d280699 100755
--- a/docutils/test/test_transforms/test_peps.py
+++ b/docutils/test/test_transforms/test_peps.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.peps.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_sectnum.py b/docutils/test/test_transforms/test_sectnum.py
index 8c3c52e6f..bf1ad6811 100755
--- a/docutils/test/test_transforms/test_sectnum.py
+++ b/docutils/test/test_transforms/test_sectnum.py
@@ -9,9 +9,14 @@ Tests for `docutils.transforms.parts.SectNum` (via
`docutils.transforms.universal.LastReaderPending`).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_smartquotes.py b/docutils/test/test_transforms/test_smartquotes.py
index 253bb3ef7..c7a1ee1cd 100644
--- a/docutils/test/test_transforms/test_smartquotes.py
+++ b/docutils/test/test_transforms/test_smartquotes.py
@@ -15,9 +15,14 @@
Test module for universal.SmartQuotes transform.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_strip_comments.py b/docutils/test/test_transforms/test_strip_comments.py
index f6cc3ad16..512c3a9a3 100755
--- a/docutils/test/test_transforms/test_strip_comments.py
+++ b/docutils/test/test_transforms/test_strip_comments.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.universal.StripComments.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_strip_elements_with_class.py b/docutils/test/test_transforms/test_strip_elements_with_class.py
index e7a1d8e2e..1dc90e20d 100644
--- a/docutils/test/test_transforms/test_strip_elements_with_class.py
+++ b/docutils/test/test_transforms/test_strip_elements_with_class.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.universal.StripClassesAndElements.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_substitution_expansion_length_limit.py b/docutils/test/test_transforms/test_substitution_expansion_length_limit.py
index 108913f2e..f862855ec 100644
--- a/docutils/test/test_transforms/test_substitution_expansion_length_limit.py
+++ b/docutils/test/test_transforms/test_substitution_expansion_length_limit.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.references.Substitutions.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_substitutions.py b/docutils/test/test_transforms/test_substitutions.py
index 2ef7fff46..7247d4931 100755
--- a/docutils/test/test_transforms/test_substitutions.py
+++ b/docutils/test/test_transforms/test_substitutions.py
@@ -8,9 +8,14 @@
Tests for docutils.transforms.references.Substitutions.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_target_notes.py b/docutils/test/test_transforms/test_target_notes.py
index a9b414e58..8ac64d6f3 100755
--- a/docutils/test/test_transforms/test_target_notes.py
+++ b/docutils/test/test_transforms/test_target_notes.py
@@ -9,9 +9,14 @@ Tests for `docutils.transforms.references.TargetNotes` (via
`docutils.transforms.universal.LastReaderPending`).
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_transitions.py b/docutils/test/test_transforms/test_transitions.py
index dd01a2f8a..56bbc4286 100755
--- a/docutils/test/test_transforms/test_transitions.py
+++ b/docutils/test/test_transforms/test_transitions.py
@@ -8,9 +8,14 @@
Test module for misc.Transitions transform.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_transforms/test_writer_aux.py b/docutils/test/test_transforms/test_writer_aux.py
index 065d72319..248adb1c5 100755
--- a/docutils/test/test_transforms/test_writer_aux.py
+++ b/docutils/test/test_transforms/test_writer_aux.py
@@ -8,9 +8,14 @@
Test module for writer_aux transforms.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.frontend import get_default_settings
from docutils.parsers.rst import Parser
diff --git a/docutils/test/test_traversals.py b/docutils/test/test_traversals.py
index 587897571..787d196f7 100755
--- a/docutils/test/test_traversals.py
+++ b/docutils/test/test_traversals.py
@@ -8,8 +8,15 @@
Test module for traversals.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
import docutils
from docutils import core, nodes, writers
diff --git a/docutils/test/test_viewlist.py b/docutils/test/test_viewlist.py
index 8a6e276d3..678952346 100755
--- a/docutils/test/test_viewlist.py
+++ b/docutils/test/test_viewlist.py
@@ -8,8 +8,15 @@
Test module for the ViewList class from statemachine.py.
"""
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[1]))
+
from docutils import statemachine
diff --git a/docutils/test/test_writers/test_get_writer_class.py b/docutils/test/test_writers/test_get_writer_class.py
index 9ebf6fb3b..4713cad56 100644
--- a/docutils/test/test_writers/test_get_writer_class.py
+++ b/docutils/test/test_writers/test_get_writer_class.py
@@ -9,9 +9,19 @@
test get_writer_class
"""
+from pathlib import Path
+import sys
import unittest
-from docutils.writers import get_writer_class
+# Prepend the "docutils root" to the Python library path
+# so we import the local `docutils` and `test` packages.
+# Ensure `test` package can be loaded also if not running as __main__
+# (required by ``python -m unittest``
+DOCUTILS_ROOT = Path(__file__).parents[2]
+if str(DOCUTILS_ROOT) not in sys.path:
+ sys.path.insert(0, str(DOCUTILS_ROOT))
+
+from docutils.writers import get_writer_class # noqa: E402
class GetWriterClassTestCase(unittest.TestCase):
@@ -25,8 +35,8 @@ class GetWriterClassTestCase(unittest.TestCase):
get_writer_class('nope')
def test_local_writer(self):
- # requires local-writer.py in test directory (testroot)
- get_writer_class('local-writer')
+ # imports local-writer.py from the test package (added above)
+ get_writer_class('test.local-writer')
# raises ImportError on failure
diff --git a/docutils/test/test_writers/test_html4css1_parts.py b/docutils/test/test_writers/test_html4css1_parts.py
index f9ff23764..b39981d9b 100755
--- a/docutils/test/test_writers/test_html4css1_parts.py
+++ b/docutils/test/test_writers/test_html4css1_parts.py
@@ -12,9 +12,14 @@ dictionaries (redundant), along with 'meta' and 'stylesheet' entries with
standard values, and any entries with empty values.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
import docutils
import docutils.core
diff --git a/docutils/test/test_writers/test_html5_polyglot_misc.py b/docutils/test/test_writers/test_html5_polyglot_misc.py
index e6631febf..eaae58aea 100644
--- a/docutils/test/test_writers/test_html5_polyglot_misc.py
+++ b/docutils/test/test_writers/test_html5_polyglot_misc.py
@@ -9,8 +9,15 @@ Miscellaneous HTML writer tests.
"""
import os
+from pathlib import Path
+import sys
import unittest
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
+
from docutils import core
# TEST_ROOT is ./test/ from the docutils root
diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py
index 0325300f7..e34f3cdd7 100644
--- a/docutils/test/test_writers/test_html5_polyglot_parts.py
+++ b/docutils/test/test_writers/test_html5_polyglot_parts.py
@@ -12,9 +12,14 @@ dictionaries (redundant), along with 'meta' and 'stylesheet' entries with
standard values, and any entries with empty values.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
import docutils
import docutils.core
diff --git a/docutils/test/test_writers/test_html5_template.py b/docutils/test/test_writers/test_html5_template.py
index caa4bbfab..b85aaa55e 100644
--- a/docutils/test/test_writers/test_html5_template.py
+++ b/docutils/test/test_writers/test_html5_template.py
@@ -10,9 +10,14 @@ Tests for the HTML writer.
import os
import platform
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
import docutils
from docutils.core import publish_string
diff --git a/docutils/test/test_writers/test_manpage.py b/docutils/test/test_writers/test_manpage.py
index b7f611ff3..799e7c771 100644
--- a/docutils/test/test_writers/test_manpage.py
+++ b/docutils/test/test_writers/test_manpage.py
@@ -7,9 +7,14 @@
Tests for manpage writer.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.core import publish_string
diff --git a/docutils/test/test_writers/test_null.py b/docutils/test/test_writers/test_null.py
index ac8a726c9..3f3b26d73 100755
--- a/docutils/test/test_writers/test_null.py
+++ b/docutils/test/test_writers/test_null.py
@@ -8,9 +8,14 @@
Test for Null writer.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.core import publish_string
diff --git a/docutils/test/test_writers/test_odt.py b/docutils/test/test_writers/test_odt.py
index d9019bb78..23e3c4a83 100755
--- a/docutils/test/test_writers/test_odt.py
+++ b/docutils/test/test_writers/test_odt.py
@@ -30,11 +30,18 @@ Instructions for adding a new test:
"""
+from io import BytesIO
+from pathlib import Path
import os
-import zipfile
-import xml.etree.ElementTree as etree
+import sys
import unittest
-from io import BytesIO
+import xml.etree.ElementTree as etree
+import zipfile
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
import docutils
import docutils.core
diff --git a/docutils/test/test_writers/test_pseudoxml.py b/docutils/test/test_writers/test_pseudoxml.py
index 3f7f80592..a15729dcb 100755
--- a/docutils/test/test_writers/test_pseudoxml.py
+++ b/docutils/test/test_writers/test_pseudoxml.py
@@ -8,9 +8,14 @@
Test for pseudo-XML writer.
"""
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
from docutils.core import publish_string
diff --git a/docutils/test/test_writers/test_s5.py b/docutils/test/test_writers/test_s5.py
index 0d6cee6f2..f1705f059 100755
--- a/docutils/test/test_writers/test_s5.py
+++ b/docutils/test/test_writers/test_s5.py
@@ -10,9 +10,14 @@ Tests for the S5/HTML writer.
import os
import platform
+from pathlib import Path
+import sys
import unittest
-from test import DocutilsTestSupport # NoQA: F401
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).parents[2]))
import docutils
from docutils.core import publish_string