question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests folder installed in site-packages

See original GitHub issue

Describe the bug I am not sure if this is a bug or something weird I am not understanding but when I installed the package, the tests folder was installed within site-packages instead of within this library folder which is causing that anything with my project’s tests module is not importable. Within site-packages I can see the datamodel_code_generator library but then I noticed that there is a tests which is in conflict with my project’s tests module.

Since I am using conda I have a pth file for my project’s modules there and they do not take priority over site-packages ones. This is causing that when I try to import something from tests like from tests.blah import Blah it will say that tests.blah does not exist because it is trying to find it within the tests module of datamodel-code-generator.

To Reproduce I just installed the package in a conda environment as normal. This caused the tests folder to be within site-packages instead of contained within its own package.

Expected behavior I would expect that the tests of the code generator are contained within the code generator package when installed. This can cause any project that is not setting their own modules via sys.path or PYTHONPATH to have conflicts if they have a module named tests they need to import. Since conda supports pth files within site-packages to define where to find local modules for a given environment this can be an issue for anyone using conda.

Version:

  • OS: MacOS 11.4
  • Python version: 3.8.5
  • datamodel-code-generator version: 0.11.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jaraqueffdccommented, Aug 13, 2021

Great thanks!

2reactions
koxudaxicommented, Aug 12, 2021

@jaraqueffdc @gaborbernat I have fixed the problem 🎉

$ curl  https://files.pythonhosted.org/packages/72/c8/267aa613c1c0124883acc2de2f2163ff0a4d889f407346de4d4e43f60eab/datamodel_code_generator-0.11.11-py3-none-any.whl -o datamodel_code_generator-0.11.11-py3-none-any.whl 2>/dev/null
$ zipinfo ./datamodel_code_generator-0.11.11-py3-none-any.whl | grep 'tests/' | wc -l
0
Read more comments on GitHub >

github_iconTop Results From Across the Web

get site-packages folder from a python unittest - Stack Overflow
So you want your local development version to use unittests from whatever the system-level installed package has? That seems like a bad idea...
Read more >
Python Packaging: Local Installation & Tests Before Uploading
Locally installing and testing a Python library is such a good idea especially before uploading it to PyPI. You might have tested the...
Read more >
Good Integration Practices — pytest documentation
You can then install your package in “editable” mode by running from the same directory: pip install -e . which lets you change...
Read more >
Typical Directory structure for python tests - GitHub Gist
A Typical directory structure for running tests using unittest ... And in the test modules inside the test package, you can import the...
Read more >
4. Package structure and distribution
Without a “src” folder, Python will find your package as it exists in the current directory and import it, rather than using it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found