(Black) Formatter & Pytest fail with .env in Python
See original GitHub issueEnvironment data
VSCode: Most recent non-insider version. Python: 3.7 Black: Most recent.
Expected behaviour
Black is registered as a formatter. Code is formatted.
Actual behaviour
Nothing happens.
Steps to reproduce:
Working:
- Register black as the formatter of choice.
- Create a directory with the following structure:
root
- project
- file_to_be_formatted.py
- Add some code into
file_to_be_formatted.py
that has formatting issues. - Run black with
alt + shift + f
. It formats the code!
Failing:
- Register black as the formatter of choice.
- Create a directory with the following structure:
root
- .env (This contains "PYTHONPATH=./project" to make properly configure package detection, etc.)
- project
- file_to_be_formatted.py
- Add some code into
file_to_be_formatted.py
that has formatting issues. - Run black with
alt + shift + f
. It does not format the code
So having a .env
file will silently make black fail. Running black from the command line on file_to_be_formatted.py
does still work
I follow this: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings
Issue Analytics
- State:
- Created 4 years ago
- Comments:16
Top Results From Across the Web
GitLab CI Python black formatter says: would reformat ...
GitLab CI Python black formatter says: would reformat, whereas running black does not reformat - Stack Overflow. Stack Overflow for Teams – ...
Read more >pytest-black - PyPI
To run pytest with formatting checks provided by black: $ pytest --black. The plugin will output a diff of suggested formatting changes (if...
Read more >Consistent Python code with Black - Matt Layman
This post focuses on Black, a code formatter, how it can improve your ... You could also use a tool like Pipenv to...
Read more >Use black, mypy, and pylint to make your Python code more ...
Importantly, you need to choose black as the formatter and choose mypy and pylint for linting. The specific arguments are optional and can...
Read more >The basics - Black 22.12.0 documentation
Development on the latest version of Python is preferred. ... Install development dependencies inside a virtual environment of your choice, for example:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I upvoted all of the above. I’ll restructured my project to
.env
and no additional settings insettings.json
.jedi disabled
.With this setup VSCode:
Test
tabpip install -e .
from the project rootSounds good 👍 I’ll close this issue as resolved, but you’re welcome to comment here if you encounter issues further down the road and we can reopen it 🙂