@@ -117,7 +117,7 @@ def py_binary(name, srcs = [], main = None, **kwargs):
117117
118118 _py_binary_or_test (name = name , rule = _py_binary , srcs = srcs , main = main , resolutions = resolutions , ** kwargs )
119119
120- def py_test (name , srcs = [], main = None , ** kwargs ):
120+ def py_test (name , srcs = [], main = None , pytest_main_deps = None , ** kwargs ):
121121 """Identical to [py_binary](./py_binary.md), but produces a target that can be used with `bazel test`.
122122
123123 Args:
@@ -127,6 +127,8 @@ def py_test(name, srcs = [], main = None, **kwargs):
127127 Like rules_python, this is treated as a suffix of a file that should appear among the srcs.
128128 If absent, then `[name].py` is tried. As a final fallback, if the srcs has a single file,
129129 that is used as the main.
130+ pytest_main_deps: List of labels. If set, generate a [py_pytest_main](#py_pytest_main) script and use it as the py_test entry point.
131+ The supplied labels define the deps attribute for the generated py_pytest_main.
130132 **kwargs: additional named parameters to `py_binary_rule`.
131133 """
132134
@@ -139,4 +141,15 @@ def py_test(name, srcs = [], main = None, **kwargs):
139141 if resolutions :
140142 resolutions = resolutions .to_label_keyed_dict ()
141143
142- _py_binary_or_test (name = name , rule = _py_test , srcs = srcs , main = main , resolutions = resolutions , ** kwargs )
144+ deps = kwargs .pop ("deps" , [])
145+ if pytest_main_deps :
146+ pytest_main_target = name + ".pytest_main"
147+ main = pytest_main_target + ".py"
148+ py_pytest_main (
149+ name = pytest_main_target ,
150+ deps = pytest_main_deps ,
151+ )
152+ srcs .append (main )
153+ deps .append (pytest_main_target )
154+
155+ _py_binary_or_test (name = name , rule = _py_test , srcs = srcs , deps = deps , main = main , resolutions = resolutions , ** kwargs )
0 commit comments