grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
387 stars 21 forks source link

Fix the test suite #74

Closed hauntsaninja closed 2 years ago

hauntsaninja commented 2 years ago

Fixes #72

This is a fun one, involving:

You'll notice that almost every subcombination of those four things is bad.

Monkeypatching mypyc-compiled modules doesn't work. The import order in test_blue.py meant that while running tests, we imported black before blue. So it was too late for NoMypycBlackFileFinder to do its thing. So that explains failures, but not successes. black uses multiprocessing internally. In Python 3.8 on macOS, the default start method changed to spawn from fork. I'm guessing in the child process the code runs in the order we want and patching works.

I changed bad_cases/demo.py to be correctly black formatted. Might be useful to have a test that enforces this.

warsaw commented 2 years ago

@hauntsaninja Awesome bit of sleuthing, thanks!

In Python 3.8 on macOS, the default start method changed to spawn from fork.

This explains the failure difference locally (macOS) vs CI (Linux) where it also fails on 3.9.