Add new special visibility type `//visibility:testonly`
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
It is common for us to create a library and want to lock down visibility to only certain parts of the application, but then when an integration test is written it becomes very difficult for that test to depend on the libraries it needs for making assertions.
This leads to us having long `visibility` lists that are basically one or two real places that are expected, and then dozens of packages with tests.
It also requires us to move those tests into their own package, so that sibling targets do not also inappropriately gain visibility into the private code.
It would be nice to have a `//visibility:testonly` pseudo_package_group that grants visibility to any target that is marked as `testonly = True`.
I recognize that this would be a bit weird, since _targets_ are marked with `testonly`, but visibility is done at the _package_ level. That might be enough of a problem to prevent this from being feasible, but I'm hoping that there is some way around this problem.
### Which category does this issue belong to?
Loading API
Contributor guide
Research direction
Start with Bazel's Loading API and trace how visibility is represented at the package level versus how targets receive testonly = True. Determine whether a //visibility:testonly pseudo_package_group can be defined without changing those boundaries; done means the proposal is either implemented with coverage for visibility and testonly behavior or documented as infeasible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100