Skip to content
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 mark.it titles when used with mark.parametrize #23

Merged
merged 5 commits into from
Apr 18, 2019

Conversation

RomuloOliveira
Copy link
Collaborator

Allow use of custom titles using pytest.mark.it along with parametrized tests. Fixes #22.

When mark.parametrize is used, pytest includes the parameters in the last part of nodeid (e.g. test_module_name.py::test_a_passing_test[this is a param]).
I used the fact that function names cannot contain brackets to safely extract parameters. Parameters may include brackets, though.

I think function names and arguments I wrote may need a more thorough review.

@RomuloOliveira
Copy link
Collaborator Author

@cartertinney could you please test if this will do the job for the cases you're working on? You can test using pip install git+https://github.com/renanivo/pytest-testdox.git@ro-mark-it-parametrize-fix.

@renanivo I've marked as a draft pull request until you or @cartertinney can confirm that it work as expected.

Here the output for some tests I did:

    @pytest.mark.parametrize('a_param', [
        'String',
        1234,
        [],
        {}
    ])
    @pytest.mark.it('It should display a nice name')
    def test_foobar(self, a_param):
        assert True
Include Parametrized
 ✓ It should display a nice name[String]
 ✓ It should display a nice name[1234]
 ✓ It should display a nice name[a_param2]
 ✓ It should display a nice name[a_param3]

Without using pytest-testdox, this is the output with -vv:

tests/test_formatters.py::TestIncludeParametrized::test_foobar[String] PASSED                                              [ 25%]
tests/test_formatters.py::TestIncludeParametrized::test_foobar[1234] PASSED                                                [ 50%]
tests/test_formatters.py::TestIncludeParametrized::test_foobar[a_param2] PASSED                                            [ 75%]
tests/test_formatters.py::TestIncludeParametrized::test_foobar[a_param3] PASSED                                            [100%]

@codecov
Copy link

codecov bot commented Apr 17, 2019

Codecov Report

Merging #23 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #23   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           5      5           
  Lines         185    193    +8     
=====================================
+ Hits          185    193    +8
Impacted Files Coverage Δ
pytest_testdox/formatters.py 100% <100%> (ø) ⬆️
pytest_testdox/models.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4778827...c8f06de. Read the comment docs.

@renanivo renanivo marked this pull request as ready for review April 18, 2019 02:58
Copy link
Owner

@renanivo renanivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Great! 👏

tests/test_plugin.py Outdated Show resolved Hide resolved
tests/test_plugin.py Outdated Show resolved Hide resolved
@cartertinney
Copy link

cartertinney commented Apr 18, 2019

Yeah, just tried it out, working great here. Thanks a bunch. 💯

@RomuloOliveira RomuloOliveira merged commit d8df2bf into master Apr 18, 2019
@RomuloOliveira RomuloOliveira deleted the ro-mark-it-parametrize-fix branch April 18, 2019 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatibility between pytest.mark.it and pytest.mark.parametrize
3 participants