# TargetSubject `TargetSubject` wraps a [`Target`] object and provides method for asserting its state. {.starlark-object} ## TargetSubject.action_generating {.starlark-signature} TargetSubject.action_generating([short_path](#targetsubject_action_generating_short_path)) Get the single action generating the given path. Method: TargetSubject.action_generating NOTE: in order to use this method, the target must have the `TestingAspectInfo` provider (added by the `testing_aspect` aspect.) {#targetsubject_action_generating_parameters} **PARAMETERS** [¶](#targetsubject_action_generating_parameters){.headerlink} :[short_path[¶](#targetsubject_action_generating_short_path){.headerlink}]{.span}: []{#targetsubject_action_generating_short_path} ([`str`]) the output's short_path to match. The value is formatted using [`format_str`], so its template keywords can be directly passed. {#targetsubject_action_generating_returns} RETURNS [¶](#targetsubject_action_generating_returns){.headerlink} : [`ActionSubject`] for the matching action. If no action is found, or more than one action matches, then an error is raised. {.starlark-object} ## TargetSubject.action_named {.starlark-signature} TargetSubject.action_named([mnemonic](#targetsubject_action_named_mnemonic)) Get the single action with the matching mnemonic. Method: TargetSubject.action_named NOTE: in order to use this method, the target must have the [`TestingAspectInfo`] provider (added by the [`testing_aspect`] aspect.) {#targetsubject_action_named_parameters} **PARAMETERS** [¶](#targetsubject_action_named_parameters){.headerlink} :[mnemonic[¶](#targetsubject_action_named_mnemonic){.headerlink}]{.span}: []{#targetsubject_action_named_mnemonic} ([`str`]) the mnemonic to match {#targetsubject_action_named_returns} RETURNS [¶](#targetsubject_action_named_returns){.headerlink} : [`ActionSubject`]. If no action matches, or more than one action matches, an error is raised. {.starlark-object} ## TargetSubject.attr {.starlark-signature} TargetSubject.attr([name](#targetsubject_attr_name), [factory](#targetsubject_attr_factory)=None) Gets a subject-wrapped value for the named attribute. Method: TargetSubject.attr NOTE: in order to use this method, the target must have the `TestingAspectInfo` provider (added by the `testing_aspect` aspect.) {#targetsubject_attr_parameters} **PARAMETERS** [¶](#targetsubject_attr_parameters){.headerlink} :[name[¶](#targetsubject_attr_name){.headerlink}]{.span}: []{#targetsubject_attr_name} ([`str`]) the attribute to get. If it's an unsupported attribute, and no explicit factory was provided, an error will be raised. :[factory[¶](#targetsubject_attr_factory){.headerlink}]{.span}: []{#targetsubject_attr_factory} (_default `None`_) (callable) function to create the returned subject based on the attribute value. If specified, it takes precedence over the attributes that are inherently understood. It must have the following signature: `def factory(value, *, meta)`, where `value` is the value of the attribute, and `meta` is the call chain metadata. {#targetsubject_attr_returns} RETURNS [¶](#targetsubject_attr_returns){.headerlink} : A Subject-like object for the given attribute. The particular subject type returned depends on attribute and `factory` arg. If it isn't know what type of subject to use for the attribute, an error is raised. {.starlark-object} ## TargetSubject.data_runfiles {.starlark-signature} TargetSubject.data_runfiles() Creates a subject asserting on the target's data runfiles. Method: TargetSubject.data_runfiles {#targetsubject_data_runfiles_returns} RETURNS [¶](#targetsubject_data_runfiles_returns){.headerlink} : [`RunfilesSubject`] object {.starlark-object} ## TargetSubject.default_outputs {.starlark-signature} TargetSubject.default_outputs() Creates a subject asserting on the target's default outputs. Method: TargetSubject.default_outputs {#targetsubject_default_outputs_returns} RETURNS [¶](#targetsubject_default_outputs_returns){.headerlink} : [`DepsetFileSubject`] object. {.starlark-object} ## TargetSubject.executable {.starlark-signature} TargetSubject.executable() Creates a subject asesrting on the target's executable File. Method: TargetSubject.executable {#targetsubject_executable_returns} RETURNS [¶](#targetsubject_executable_returns){.headerlink} : [`FileSubject`] object. {.starlark-object} ## TargetSubject.failures {.starlark-signature} TargetSubject.failures() Creates a subject asserting on the target's failure message strings. Method: TargetSubject.failures {#targetsubject_failures_returns} RETURNS [¶](#targetsubject_failures_returns){.headerlink} : [`CollectionSubject`] of [`str`]. {.starlark-object} ## TargetSubject.get_attr {.starlark-signature} TargetSubject.get_attr([name](#targetsubject_get_attr_name)) {#targetsubject_get_attr_parameters} **PARAMETERS** [¶](#targetsubject_get_attr_parameters){.headerlink} :[name[¶](#targetsubject_get_attr_name){.headerlink}]{.span}: []{#targetsubject_get_attr_name} _undocumented_ {.starlark-object} ## TargetSubject.has_provider {.starlark-signature} TargetSubject.has_provider([provider](#targetsubject_has_provider_provider), [provider_name](#targetsubject_has_provider_provider_name)="") Asserts that the target as provider `provider`. Method: TargetSubject.has_provider {#targetsubject_has_provider_parameters} **PARAMETERS** [¶](#targetsubject_has_provider_parameters){.headerlink} :[provider[¶](#targetsubject_has_provider_provider){.headerlink}]{.span}: []{#targetsubject_has_provider_provider} The provider object to check for. :[provider_name[¶](#targetsubject_has_provider_provider_name){.headerlink}]{.span}: []{#targetsubject_has_provider_provider_name} (_default `""`_) The display name of the provider {.starlark-object} ## TargetSubject.label {.starlark-signature} TargetSubject.label() Returns a `LabelSubject` for the target's label value. Method: TargetSubject.label {.starlark-object} ## TargetSubject.new {.starlark-signature} TargetSubject.new([target](#targetsubject_new_target), [meta](#targetsubject_new_meta)) Creates a subject for asserting Targets. Method: TargetSubject.new **Public attributes**: * `actual`: The wrapped [`Target`] object. {#targetsubject_new_parameters} **PARAMETERS** [¶](#targetsubject_new_parameters){.headerlink} {.params-box} :[target[¶](#targetsubject_new_target){.headerlink}]{.span}: []{#targetsubject_new_target} ([`Target`]) the target to check against. :[meta[¶](#targetsubject_new_meta){.headerlink}]{.span}: []{#targetsubject_new_meta} ([`ExpectMeta`]) metadata about the call chain. {#targetsubject_new_returns} RETURNS [¶](#targetsubject_new_returns){.headerlink} : [`TargetSubject`] object {.starlark-object} ## TargetSubject.output_group {.starlark-signature} TargetSubject.output_group([name](#targetsubject_output_group_name)) Returns a DepsetFileSubject of the files in the named output group. Method: TargetSubject.output_group {#targetsubject_output_group_parameters} **PARAMETERS** [¶](#targetsubject_output_group_parameters){.headerlink} :[name[¶](#targetsubject_output_group_name){.headerlink}]{.span}: []{#targetsubject_output_group_name} ([`str`]) an output group name. If it isn't present, an error is raised. {#targetsubject_output_group_returns} RETURNS [¶](#targetsubject_output_group_returns){.headerlink} : DepsetFileSubject of the named output group. {.starlark-object} ## TargetSubject.provider {.starlark-signature} TargetSubject.provider([provider_key](#targetsubject_provider_provider_key), [factory](#targetsubject_provider_factory)=None, [provider_name](#targetsubject_provider_provider_name)="") Returns a subject for a provider in the target. Method: TargetSubject.provider {#targetsubject_provider_parameters} **PARAMETERS** [¶](#targetsubject_provider_parameters){.headerlink} :[provider_key[¶](#targetsubject_provider_provider_key){.headerlink}]{.span}: []{#targetsubject_provider_provider_key} The provider key to create a subject for :[factory[¶](#targetsubject_provider_factory){.headerlink}]{.span}: []{#targetsubject_provider_factory} (_default `None`_) optional callable. The factory function to use to create the subject for the found provider. Required if the provider key is not an inherently supported provider. It must have the following signature: `def factory(value, /, *, meta)`. Additional types of providers can be pre-registered by using the `provider_subject_factories` arg of `analysis_test`. :[provider_name[¶](#targetsubject_provider_provider_name){.headerlink}]{.span}: []{#targetsubject_provider_provider_name} (_default `""`_) The display name of the provider. This must be supplied separately because str(provider_key) just returns "", which isn't helpful. For lack of a better option, this defaults to . {#targetsubject_provider_returns} RETURNS [¶](#targetsubject_provider_returns){.headerlink} : A subject wrapper of the provider value. {.starlark-object} ## TargetSubject.runfiles {.starlark-signature} TargetSubject.runfiles() Creates a subject asserting on the target's default runfiles. Method: TargetSubject.runfiles {#targetsubject_runfiles_returns} RETURNS [¶](#targetsubject_runfiles_returns){.headerlink} : [`RunfilesSubject`] object. {.starlark-object} ## TargetSubject.tags {.starlark-signature} TargetSubject.tags() Gets the target's tags as a `CollectionSubject` Method: TargetSubject.tags {#targetsubject_tags_returns} RETURNS [¶](#targetsubject_tags_returns){.headerlink} : [`CollectionSubject`] asserting the target's tags. [`Action`]: https://bazel.build/rules/lib/Action [`ActionSubject`]: /api/action_subject [`bool`]: https://bazel.build/rules/lib/bool [`BoolSubject`]: /api/bool_subject [`CollectionSubject`]: /api/collection_subject [`depset`]: https://bazel.build/rules/lib/depset [`DepsetFileSubject`]: /api/depset_file_subject [`dict`]: https://bazel.build/rules/lib/dict [`DictSubject`]: /api/dict_subject [`Expect`]: /api/expect [`ExpectMeta`]: /api/expect_meta [`File`]: https://bazel.build/rules/lib/File [`FileSubject`]: /api/file_subject [`format_str`]: /api/expect_meta.html#expectmeta-format-str [`IntSubject`]: /api/int_subject [`Label`]: https://bazel.build/rules/lib/Label [`LabelSubject`]: /api/label_subject [`list`]: https://bazel.build/rules/lib/list [`Ordered`]: /api/ordered [`RunfilesSubject`]: /api/runfiles_subject [`str`]: https://bazel.build/rules/lib/string [`struct`]: https://bazel.build/rules/lib/builtins/struct [`StrSubject`]: /api/str_subject [`StructSubject`]: /api/struct_subject [`Target`]: https://bazel.build/rules/lib/Target [`TargetSubject`]: /api/target_subject [target-name]: https://bazel.build/concepts/labels#target-names [attr-label]: https://bazel.build/concepts/labels