-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve context manager issues with Black v23.1.0 formatted tests raising AAA03 #200
Comments
Until this is solved a workaround is to add a comment: def test_with():
a_class = AClass()
with freeze_time("2021-02-02 12:00:02"):
# Remove once https://github.com/jamescooke/flake8-aaa/issues/200 is solved
result = a_class.action('test')
assert result == 'test' |
* WIP add problematic and correct code examples * Add good example of pytest.raises() and update example README * Build out problematic code / correct code for AAA01 * Fix supported Python versions docs, add Black issue #200 * Update CHANGELOG * Extend Changelog to contain markers for types of changes
Plan Of Action 🏃🏻I'm hoping that I can roll out a fix across two releases... Add a setting, next release
|
@lyz-code If you have some time to test out master, passing I'll try it out with some of my internal projects tomorrow and hopefully write up docs for a release soon, all being well 🤞🏻 . |
Hey @jamescooke thanks for the detailed issue evolution, it's very helpful. Sadly I'm a bit overwhelmed these days so sadly I'm not sure if I'll have the time to try it :(. Thank you so much for developing the fix though <3 |
Have experimented with the current master on a couple of projects using Black and everything seems to work OK. Only one caveat: Just formatting the tests with Black is not enough when those tests have context managers. When the context manager has joined the Act block, then there will need to be a blank line added above it to resolve the "AAA03 expected 1 blank line before Act block, found none" errors. I'll prep release |
Thank you so much <3 |
Problematic code
As of Black
23.1.0
(and possibly earlier versions), the solution of separating the context manager into the Arrange block and keeping the Act block simple won't work because Black now complains about the blank line after the context manager:Black wants to remove the blank link after the context manager and the action, resulting in:
However, current Flake8-AAA raises
AAA03
because there is no blank line before the Act block 😞Possible solution
One possible solution is to allow for a "greedy context manager" - the
freeze_time()
context is allowed to join the Act block, even though it's really arrangement:This passes Black, but would need some fixing on the Flake8-AAA side.
One option would be to create a setting
greedy_context_managers
or similar which can be set totrue
for Black users, but I'm concerned that the effort required to test and manage such a setting would be a weight on Flake8-AAA long term.Greedy context managers were removed in #146 released in
0.10.0
, see https://github.com/jamescooke/flake8-aaa/blob/master/CHANGELOG.rst#changed-4Paper trail
The text was updated successfully, but these errors were encountered: