Skip to content

1.1.2: pytest fails in one unit #398

Open
@kloczek

Description

@kloczek

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using 'installer` module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-sphinxcontrib-trio-1.1.2-15.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-sphinxcontrib-trio-1.1.2-15.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.18, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/tkloczko/rpmbuild/BUILD/sphinxcontrib-trio-1.1.2
plugins: datadir-1.5.0, regressions-2.5.0
collected 3 items

tests/test_sphinxcontrib_trio.py .F.                                                                                                                                                  [100%]

========================================================================================= FAILURES ==========================================================================================
______________________________________________________________________________________ test_end_to_end ______________________________________________________________________________________

tmpdir = local('/tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0')

    def test_end_to_end(tmpdir):
        shutil.copytree(str(Path(__file__).parent / "test-docs-source"),
                        str(tmpdir / "test-docs-source"))
        subprocess.run(
            ["sphinx-build", "-v", "-nW", "-nb", "html",
             str(tmpdir / "test-docs-source"), str(tmpdir / "out")])

        tree = lxml.html.parse(str(tmpdir / "out" / "test.html")).getroot()

        def do_html_test(node, *, expect_match):
            original_content = node.text_content()
            print("\n-- test case --\n", lxml.html.tostring(node, encoding="unicode"))

            check_tags = node.cssselect(".highlight-none")
            checks = []
            for tag in check_tags:
                text = tag.text_content().strip()
                # lxml normalizes &nbsp to the unicode \xa0, so we do the same
                text = text.replace("&nbsp;", "\xa0")
                checks.append(text)
                tag.drop_tree()

            # make sure we removed the tests from the top-level node, to avoid
            # potential false positives matching on the tests themselves!
            assert len(node.text_content()) < len(original_content)
            assert checks

            test_content = lxml.html.tostring(node, encoding="unicode")
            # some versions of sphinx (>= 1.6) replace "..." with the ellipsis
            # character \u2026. Normalize back to "..." for comparison
            # purposes.
            test_content = test_content.replace("\u2026", "...")
            for check in checks:
                try:
                    if expect_match:
                        assert re.search(check, test_content) is not None
                    else:
                        assert re.search(check, test_content) is None
                except AssertionError:
                    print("failed check")
                    print()
                    print(repr(check))
                    print()
                    print("failed test_content")
                    print()
                    print(repr(test_content))
                    raise

        print("\n-- NEGATIVE (WARNING) TESTS --\n")

        for warning in tree.cssselect(".warning"):
            do_html_test(warning, expect_match=False)

        print("\n-- POSITIVE (NOTE) TESTS --\n")

        for note in tree.cssselect(".note"):
>           do_html_test(note, expect_match=True)

tests/test_sphinxcontrib_trio.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

node = <Element div at 0x7f16e2bb8f90>

    def do_html_test(node, *, expect_match):
        original_content = node.text_content()
        print("\n-- test case --\n", lxml.html.tostring(node, encoding="unicode"))

        check_tags = node.cssselect(".highlight-none")
        checks = []
        for tag in check_tags:
            text = tag.text_content().strip()
            # lxml normalizes &nbsp to the unicode \xa0, so we do the same
            text = text.replace("&nbsp;", "\xa0")
            checks.append(text)
            tag.drop_tree()

        # make sure we removed the tests from the top-level node, to avoid
        # potential false positives matching on the tests themselves!
        assert len(node.text_content()) < len(original_content)
        assert checks

        test_content = lxml.html.tostring(node, encoding="unicode")
        # some versions of sphinx (>= 1.6) replace "..." with the ellipsis
        # character \u2026. Normalize back to "..." for comparison
        # purposes.
        test_content = test_content.replace("\u2026", "...")
        for check in checks:
            try:
                if expect_match:
>                   assert re.search(check, test_content) is not None
E                   assert None is not None
E                    +  where None = <function search at 0x7f16e4ed5430>('<em class="property">await </em><code class="(sig-name )?descname">foo</code>', '<div class="admonition note">\n<p class="admonition-title">Note</p>\n<dl class="py function">\n<dt class="sig sig-obj... class="n"><span class="pre">bar</span></span></em><span class="sig-paren">)</span></dt>\n<dd></dd></dl>\n\n\n</div>\n')
E                    +    where <function search at 0x7f16e4ed5430> = re.search

tests/test_sphinxcontrib_trio.py:220: AssertionError
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Running Sphinx v7.1.2
making output directory... done
locale_dir /tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0/test-docs-source/locales/en/LC_MESSAGES does not exists
[autosummary] generating autosummary for: test.rst
[autosummary] generating autosummary for: /tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0/test-docs-source/autodoc_examples.autosummary_me.rst
locale_dir /tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0/test-docs-source/locales/en/LC_MESSAGES does not exists
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 1 source files that are out of date
updating environment: locale_dir /tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0/test-docs-source/locales/en/LC_MESSAGES does not exists
[new config] 2 added, 0 changed, 0 removed
reading sources... [ 50%] autodoc_examples.autosummary_me
reading sources... [100%] test

looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... copying static files... done
copying extra files... done
done
writing output... [ 50%] autodoc_examples.autosummary_me
writing output... [100%] test

generating indices... genindex py-modindex done
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.

The HTML pages are in ../../../../../tmp/pytest-of-tkloczko/pytest-69/test_end_to_end0/out.

-- NEGATIVE (WARNING) TESTS --


-- test case --
 <div class="admonition warning">
<p class="admonition-title">Warning</p>
<dl class="py function">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">foo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bar</span></span></em><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&lt;em class="property"&gt;await &lt;/em&gt;&lt;code class="(sig-name )?descname"&gt;foo&lt;/code&gt;
</pre></div>
</div>
</div>


-- test case --
 <div class="admonition warning">
<p class="admonition-title">Warning</p>
<dl class="py function">
<dt class="sig sig-object py">
<span class="sig-prename descclassname"><span class="pre">autodoc_examples.</span></span><span class="sig-name descname"><span class="pre">basic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&lt;/em&gt;&lt;code class="(sig-name )?descname"&gt;basic&lt;/code&gt;
</pre></div>
</div>
</div>


-- test case --
 <div class="admonition warning">
<p class="admonition-title">Warning</p>
<dl class="py class">
<dt class="sig sig-object py">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">autodoc_examples.</span></span><span class="sig-name descname"><span class="pre">ExampleInheritedSubclass</span></span></dt>
<dd><dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">a_syncmethod</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">b_syncmethod</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<em class="property"><span class="pre">await</span> </em><span class="sig-name descname"><span class="pre">c_asyncmethod</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py">
<em class="property"><span class="pre">await</span> </em><span class="sig-name descname"><span class="pre">d_asyncmethod</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

</dd></dl>

<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&lt;em class="property"&gt;await &lt;/em&gt;&lt;code class="(sig-name )?descname"&gt;a_syncmethod&lt;/code&gt;
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&lt;em class="property"&gt;await &lt;/em&gt;&lt;code class="(sig-name )?descname"&gt;b_syncmethod&lt;/code&gt;
</pre></div>
</div>
</div>


-- test case --
 <div class="admonition warning">
<p class="admonition-title">Warning</p>
<dl class="py function">
<dt class="sig sig-object py">
<span class="sig-prename descclassname"><span class="pre">autodoc_examples.</span></span><span class="sig-name descname"><span class="pre">gen</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>for
</pre></div>
</div>
</div>


-- POSITIVE (NOTE) TESTS --


-- test case --
 <div class="admonition note">
<p class="admonition-title">Note</p>
<dl class="py function">
<dt class="sig sig-object py">
<em class="property"><span class="pre">await</span> </em><span class="sig-name descname"><span class="pre">foo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bar</span></span></em><span class="sig-paren">)</span></dt>
<dd></dd></dl>

<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>&lt;em class="property"&gt;await &lt;/em&gt;&lt;code class="(sig-name )?descname"&gt;foo&lt;/code&gt;
</pre></div>
</div>
</div>

failed check

'<em class="property">await </em><code class="(sig-name )?descname">foo</code>'

failed test_content

'<div class="admonition note">\n<p class="admonition-title">Note</p>\n<dl class="py function">\n<dt class="sig sig-object py">\n<em class="property"><span class="pre">await</span> </em><span class="sig-name descname"><span class="pre">foo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bar</span></span></em><span class="sig-paren">)</span></dt>\n<dd></dd></dl>\n\n\n</div>\n'
================================================================================== short test summary info ==================================================================================
FAILED tests/test_sphinxcontrib_trio.py::test_end_to_end - assert None is not None
================================================================================ 1 failed, 2 passed in 2.51s ================================================================================
List of installed modules in build env:
Package                       Version
----------------------------- -------
alabaster                     0.7.16
Babel                         2.14.0
build                         1.0.3
charset-normalizer            3.3.2
cppclean                      0.13
cssselect                     1.2.0
distro                        1.9.0
dnf                           4.18.2
docutils                      0.20.1
exceptiongroup                1.1.3
gpg                           1.23.2
idna                          3.6
imagesize                     1.4.1
importlib-metadata            7.0.1
iniconfig                     2.0.0
installer                     0.7.0
Jinja2                        3.1.3
libdnf                        0.72.0
lxml                          5.0.0
MarkupSafe                    2.1.3
packaging                     23.2
pluggy                        1.3.0
Pygments                      2.17.2
pyproject_hooks               1.0.0
pytest                        7.4.4
python-dateutil               2.8.2
pytz                          2023.3
requests                      2.31.0
setuptools                    69.0.3
six                           1.16.0
snowballstemmer               2.2.0
Sphinx                        7.1.2
sphinxcontrib-applehelp       1.0.4
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.5
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.7
sphinxcontrib-serializinghtml 1.1.10
tomli                         2.0.1
urllib3                       1.26.18
wheel                         0.42.0
zipp                          3.17.0

Please let me know if you need more details or want me to perform some diagnostics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions