Skip to content

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

Closed
@sleighsoft

Description

@sleighsoft

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

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions