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.

(Black) Formatter & Pytest fail with .env in Python

See original GitHub issue

Environment 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:

  1. Register black as the formatter of choice.
  2. Create a directory with the following structure:
root
- project
  - file_to_be_formatted.py
  1. Add some code into file_to_be_formatted.py that has formatting issues.
  2. Run black with alt + shift + f. It formats the code!

Failing:

  1. Register black as the formatter of choice.
  2. 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
  1. Add some code into file_to_be_formatted.py that has formatting issues.
  2. 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:closed
  • Created 4 years ago
  • Comments:16

github_iconTop GitHub Comments

1reaction
sleighsoftcommented, Mar 4, 2020

I upvoted all of the above. I’ll restructured my project to

.vscode
setup.py
benchit/
   format.py
   dtypes.py uses `import format` 
tests/
   test.py uses `import dtypes`
  • I have no .env and no additional settings in settings.json.
  • I have jedi disabled.

With this setup VSCode:

  • properly discovers and runs tests under the Test tab
  • properly formats with black
  • has proper auto completion and detection of my package
  • i can properly install the package with pip install -e . from the project root
0reactions
kimadelinecommented, Mar 4, 2020

Sounds 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 🙂

Read more comments on GitHub >

github_iconTop 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 >

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