Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot create an xml report #1709

Closed
gocarlos opened this issue Dec 11, 2023 · 9 comments
Closed

cannot create an xml report #1709

gocarlos opened this issue Dec 11, 2023 · 9 comments
Labels
bug Something isn't working fixed xml

Comments

@gocarlos
Copy link

gocarlos commented Dec 11, 2023

Describe the bug

I create the coverage of some tests by calling the coverage API according to the documentation, then pytest.main(... etc according to the documentation

import coverage

# running the application under `/my` but my plugin code is under `my_envs/my_model`
cov = coverage.Coverage(
            source=['/my_envs/my_model'],
            messages=True
)
cov.start()

pytest.main(...)

cov.stop()
cov.save()

# works
cov.report()

# works
cov.html_report()

# ERROR: does not work
cov.xml_report(outfile="coverage.xml")

The html report works perfectly, the stdout terminal also works...

the xml_report crashes, then tried the terminal way: coverage xml -o coverage.xml to convert the existing .coverage file to xml, same issue as with the function xml_report:

Traceback (most recent call last):
  File "/home/my_user/.local/bin/coverage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/cmdline.py", line 973, in main        
    status = CoverageScript().command_line(argv)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/cmdline.py", line 733, in command_line
    total = self.coverage.xml_report(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/control.py", line 1215, in xml_report 
    return render_report(self.config.xml_output, XmlReporter(self), morfs, self._message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/report_core.py", line 61, in render_report
    ret = reporter.report(morfs, outfile=outfile)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/xmlreport.py", line 130, in report
    for _, class_elt in human_sorted_items(pkg_data.elements.items()):
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/my_user/.local/lib/python3.11/site-packages/coverage/misc.py", line 377, in human_sorted_items
    return sorted(items, key=lambda item: (_human_key(item[0]), *item[1:]), reverse=reverse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'Element' and 'Element'

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using?
    3.11.6
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
-- sys -------------------------------------------------------
coverage_version: 7.3.2
coverage_module: /home/my_user/.local/lib/python3.11/site-packages/coverage/__init__.py
         tracer: -none-
        CTracer: available
plugins.file_tracers: -none-
plugins.configurers: -none-
plugins.context_switchers: -none-
configs_attempted: .coveragerc
                 setup.cfg
                 tox.ini
                 pyproject.toml
   configs_read: -none-
    config_file: None
config_contents: -none-
      data_file: -none-
         python: 3.11.6 (main, Nov 29 2023, 04:47:02) [GCC 10.2.1 20210110]
       platform: Linux-6.1.0-13-amd64-x86_64-with-glibc2.31
 implementation: CPython
     executable: /usr/local/bin/python
   def_encoding: utf-8
    fs_encoding: utf-8
            pid: 174
            cwd: /my
           path: /home/my_user/.local/bin
                 /usr/local/lib/python311.zip
                 /usr/local/lib/python3.11
                 /usr/local/lib/python3.11/lib-dynload
                 /home/my_user/.local/lib/python3.11/site-packages
                 /usr/local/lib/python3.11/site-packages
    environment: HOME = /home/my_user
                 PYTHON_GET_PIP_SHA256 = 9cc01665956d22b3bf057ae8287b035827bfd895da235bcea200ab3b811790b6
                 PYTHON_GET_PIP_URL = https://github.com/pypa/get-pip/raw/4cfa4081d27285bda1220a62a5ebf5b4bd749cdb/public/get-pip.py
                 PYTHON_PIP_VERSION = 23.2.1
                 PYTHON_SETUPTOOLS_VERSION = 65.5.1
                 PYTHON_VERSION = 3.11.6
   command_line: /home/my_user/.local/bin/coverage debug sys
sqlite3_sqlite_version: 3.34.1
sqlite3_temp_store: 0
sqlite3_compile_options: COMPILER=gcc-10.2.1 20210110, ENABLE_COLUMN_METADATA, ENABLE_DBSTAT_VTAB,
                 ENABLE_FTS3, ENABLE_FTS3_PARENTHESIS, ENABLE_FTS3_TOKENIZER, ENABLE_FTS4,
                 ENABLE_FTS5, ENABLE_JSON1, ENABLE_LOAD_EXTENSION, ENABLE_PREUPDATE_HOOK,
                 ENABLE_RTREE, ENABLE_SESSION, ENABLE_STMTVTAB, ENABLE_UNLOCK_NOTIFY,
                 ENABLE_UPDATE_DELETE_LIMIT, HAVE_ISNAN, LIKE_DOESNT_MATCH_BLOBS,
                 MAX_SCHEMA_RETRY=25, MAX_VARIABLE_NUMBER=250000, OMIT_LOOKASIDE,
                 SECURE_DELETE, SOUNDEX, TEMP_STORE=1, THREADSAFE=1, USE_URI

  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
annotated-types==0.6.0
anyio==4.1.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
asgiref==3.7.2
astroid==3.0.1
attrs==23.1.0
Babel==2.13.1
bcrypt==4.1.1
Cerberus==1.3.5
certifi==2023.11.17
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contextlib2==21.6.0
coverage==7.3.2
cryptography==41.0.7
cx-Oracle==8.3.0
dill==0.3.7
distlib==0.3.7
Django==4.2.7
djangorestframework==3.14.0
djangorestframework-simplejwt==5.3.0
docopt==0.6.2
drf-spectacular==0.26.5
environs==9.5.0
et-xmlfile==1.1.0
ghp-import==2.1.0
gitdb==4.0.11
GitPython==3.1.40
graphviz==0.20.1
gunicorn==21.2.0
h11==0.14.0
httpcore==1.0.2
httpx==0.25.2
idna==3.6
inflection==0.5.1
iniconfig==2.0.0
isodate==0.6.1
isort==5.13.0
jedi==0.19.1
Jinja2==3.1.2
jsonschema==4.20.0
jsonschema-specifications==2023.11.1
lxml==4.9.3
Markdown==3.5.1
MarkupSafe==2.1.3
marshmallow==3.20.1
mccabe==0.7.0
mergedeep==1.3.4
minio==7.2.0
mkdocs==1.5.3
mkdocs-material==9.4.11
mkdocs-material-extensions==1.3.1
mkdocs-render-swagger-plugin==0.1.1
mssql-django==1.3
openpyxl==3.1.2
outcome==1.3.0.post0
packaging==23.2
page-objects==1.1.0
paginate==0.5.6
paramiko==3.3.1
parso==0.8.3
pathspec==0.11.2
pem==23.1.0
pep517==0.13.1
Pillow==10.1.0
pip-api==0.0.30
pipreqs==0.4.13
platformdirs==4.0.0
plette==0.4.4
pluggy==1.3.0
psutil==5.9.6
psycopg2==2.9.9
py-markdown-table==0.4.0
pyasn1==0.5.1
pycparser==2.21
pycryptodome==3.19.0
pydantic==2.5.2
pydantic_core==2.14.5
pygit2==1.13.3
Pygments==2.17.2
PyJWT==2.8.0
pylint==3.0.2
pymdown-extensions==10.5
PyNaCl==1.5.0
pyodbc==5.0.1
pysftp==0.2.9
pysmb==1.2.9.1
PySocks==1.7.1
pytest==7.4.3
pytest-cov==4.1.0
python-box==7.1.1
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3.post1
PyYAML==6.0.1
pyyaml_env_tag==0.1
referencing==0.31.0
regex==2023.10.3
reportlab==4.0.7
requests==2.31.0
requests-file==1.5.1
requests-toolbelt==1.0.0
requirementslib==3.0.0
rpds-py==0.13.1
schema==0.7.5
selenium==4.16.0
setproctitle==1.3.3
sh==2.0.6
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
sortedcontainers==2.4.0
sqlparse==0.4.4
tomlkit==0.12.3
tqdm==4.66.1
trio==0.23.1
trio-websocket==0.11.1
typing_extensions==4.9.0
uritemplate==4.1.1
urllib3==2.1.0
validators==0.22.0
watchdog==3.0.0
webcolors==1.13
whitenoise==6.6.0
wsproto==1.2.0
xlrd==2.0.1
yarg==0.1.9
zeep==4.2.1
  1. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.

its clients code, that I can't share

Expected behavior
the coverage.xml file exists, no errors

@gocarlos gocarlos added bug Something isn't working needs triage labels Dec 11, 2023
@gocarlos
Copy link
Author

copied the .coverage file as well as the source code from a kubernetes pod to a windows machine and executed there again coverage xml -o coverage.xml on the same folder as the .coverage file -> same error

@nedbat
Copy link
Owner

nedbat commented Dec 11, 2023

It looks like you have two different files which are reported at the same location. For example, two files both known as module/code.py. Do you have multiple source settings? Can you provide me with the .coverage file, or the output of coverage debug data?

@nedbat
Copy link
Owner

nedbat commented Dec 11, 2023

No, sorry, you have files with numbers in their names, and some have leading zeros, like two files: x1y.py and x01y.py, is that correct?

@nedbat
Copy link
Owner

nedbat commented Dec 12, 2023

Fixed in commit be28121

@gocarlos
Copy link
Author

No, sorry, you have files with numbers in their names, and some have leading zeros, like two files: x1y.py and x01y.py, is that correct?

yes, we have a lot of files like gk_npool_01.py or VEF06_PK_D.py

@gocarlos
Copy link
Author

Fixed in commit be28121

just tested locally with the .coverage file and it works as expected!
thank you very much for the fast feedback and response

could I ask to create a trigger patch release with this fix in it?

thank you

@nedbat
Copy link
Owner

nedbat commented Dec 12, 2023

There will be a release soon.

@nedbat
Copy link
Owner

nedbat commented Dec 14, 2023

This is now released as part of coverage 7.3.3.

@gocarlos
Copy link
Author

@nedbat thank you very much 🍰

renovate bot referenced this issue in allenporter/flux-local Dec 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [coverage](https://togithub.com/nedbat/coveragepy) | `==7.3.2` ->
`==7.3.3` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/coverage/7.3.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/coverage/7.3.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/coverage/7.3.2/7.3.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/coverage/7.3.2/7.3.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>nedbat/coveragepy (coverage)</summary>

###
[`v7.3.3`](https://togithub.com/nedbat/coveragepy/blob/HEAD/CHANGES.rst#Version-733--2023-12-14)

[Compare
Source](https://togithub.com/nedbat/coveragepy/compare/7.3.2...7.3.3)

- Fix: function definitions with multi-line signatures can now be
excluded by
matching any of the lines, closing `issue 684`*. Thanks, `Jan Rusak,
    Maciej Kowalczyk and Joanna Ejzel <pull 1705_>`*.

- Fix: XML reports could fail with a TypeError if files had numeric
components
    that were duplicates except for leading zeroes, like `file1.py` and
    `file001.py`.  Fixes `issue 1709`\_.

- The `coverage annotate` command used to announce that it would be
removed
in a future version. Enough people got in touch to say that they use it,
so
it will stay. Don't expect it to keep up with other new features though.

-   Added new :ref:`debug options <cmd_run_debug>`:

    -   `pytest` writes the pytest test name into the debug output.

- `dataop2` writes the full data being added to CoverageData objects.

.. \_issue
684:[https://github.com/nedbat/coveragepy/issues/684](https://togithub.com/nedbat/coveragepy/issues/684)4
.. \_pull
1705[https://github.com/nedbat/coveragepy/pull/1705](https://togithub.com/nedbat/coveragepy/pull/1705)05
.. \_issue
170[https://github.com/nedbat/coveragepy/issues/1709](https://togithub.com/nedbat/coveragepy/issues/1709)709

.. \_changes\_7-3-2:

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/allenporter/flux-local).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy45My4xIiwidXBkYXRlZEluVmVyIjoiMzcuOTMuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed xml
Projects
None yet
Development

No branches or pull requests

2 participants