-
Notifications
You must be signed in to change notification settings - Fork 516
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
fix: make conftest.py special with gazelle #879
Conversation
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
@@ -0,0 +1,12 @@ | |||
import unittest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the __test__.py
file a gazelle convention that automatically becomes the test entrypoint, or is it generated? Reason I'm asking is this file name doesn't seem to match the allowed test patterns in generate, but gets included in the py_test sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's special for Gazelle. The following is the main logic (though they are used in some other places).
rules_python/gazelle/generate.go
Lines 27 to 28 in 24a8b74
pyTestEntrypointFilename = "__test__.py" | |
pyTestEntrypointTargetname = "__test__" |
rules_python/gazelle/generate.go
Lines 82 to 83 in 24a8b74
} else if !hasPyTestFile && f == pyTestEntrypointFilename { | |
hasPyTestFile = true |
rules_python/gazelle/generate.go
Lines 271 to 275 in 24a8b74
if hasPyTestFile { | |
// Only add the pyTestEntrypointFilename to the pyTestFilenames if | |
// the file exists on disk. | |
pyTestFilenames.Add(pyTestEntrypointFilename) | |
} |
This allows the conftest.py to be used on sub-directories as pytest would pick them up. Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
Trying to upgrade from |
@ewhauser I just got one of these myself. I'm not sure yet what causes it, but if I clear the BUILD file and ask Gazelle to generate it again, it does the right thing. I'll work on a fix. |
Hi @f0rmiga. Any progress on a fix? Minimally, I feel like this feature should be documented in the top-level README. Perhaps, also add a flag to disable it if you want to handle As a future feature idea, it would be great if the generated |
* fix: add conftest.py to py_test generated targets Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> * fix: use separate py_library for conftest.py This allows the conftest.py to be used on sub-directories as pytest would pick them up. Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> * fix: add testonly to conftest py_library Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> * fix: testonly is a boolean, not a string Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
conftest.py
is a special file that should be used only with tests, so we create apy_library
for it and add it as a dependency topy_test
. By special-casing it, we take advantage of all the dependency resolution Gazelle offers. In contrast, when adding it to apy_test
with# keep
and excluding it from Gazelle, we also have to manage its dependencies manually.