allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
719 stars 235 forks source link

Add py.typed marker files to conform PEP-561 and better typechecking #731

Open jorektheglitch opened 1 year ago

jorektheglitch commented 1 year ago

[//]: # ( . Note: for support questions, please use Stackoverflow or Gitter. . This repository's issues are reserved for feature requests and bug reports. . . In case of any problems with Allure Jenkins plugin please use the following repository . to create an issue: https://github.com/jenkinsci/allure-plugin/issues . . Make sure you have a clear name for your issue. The name should start with a capital . letter and no dot is required in the end of the sentence. An example of good issue names: . . - The report is broken in IE11 . - Add an ability to disable default plugins . - Support emoji in test descriptions )

I'm submitting a ...

What is the current behavior?

Mypy typechecker assumes that allure lib is untyped and shows various error messages. Any method decorated with allure.step is NOT checked for typing violations (like incompatible arguments types, incompatible returning types, LSP violations in decorated methods). Theese checks just silently passes EVEN if there is something bad exists.

There is incomplete list of messages and places which theese occurs:

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Create file with following code:

import allure

@allure.step("Do nothing")
def noop() -> None:
  return

And run mypy on it. Optionaly you can enable additional options - --disallow-any-decorated, --disallow-any-unimported, --disallow-untyped-decorators

What is the expected behavior?

Since the allure sources is well-typed there is no mypy warnings in places where allure things used and allure decorators usege does not prevents detecting various violations in decorated functions.

What is the motivation / use case for changing the behavior?

Better type checking for tests.

Please tell us about your environment:

Other information

Many of theese problems just solves itself if there will py.typed file in modules, as described in PEP-561.

[//]: # ( . e.g. detailed explanation, stacktraces, related issues, suggestions . how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc )