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

Simple enhancement to @ddt decorator to make it possible to provide user-friendly test method names #2

Merged
merged 3 commits into from Oct 3, 2012

Conversation

santtu
Copy link
Contributor

@santtu santtu commented Sep 28, 2012

Basically, this allows to do something like:

def make_data(...):
    d = ...
    setattr(d, "__name__", "friendly_name_computed_from_data")
    return d

@dds
class ...:
    @data(make_data(...), make_data(....), make_data(...))
    def test_much_data(self, data):
        ....

Unless __name__ is in the data, the current formatting behavior is used.

Allows to provide user-friendly names for the user instead of
the default raw data formatting.
@txels
Copy link
Collaborator

txels commented Sep 29, 2012

Nice idea. Could you add a simple test case in test_functional and a note in the docs in example.rst?

Also moved the document example to be a real test case to make sure
it is also tested (so it is not accidentally broken).
@santtu
Copy link
Contributor Author

santtu commented Sep 30, 2012

Here you go.

By the way, are you sure about how feed_data is used? Check out test_example.py method test_greater -- if tuple/list is given in @data, it is passed as-is and not as multiple arguments to the test function (which would be more useful).

"""Test the ``__name__`` attribute handling of ``data`` items with ``ddt``"""

def hello():
passo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intentional? I know it has no impact on the test, but funnily enough in my language (catalan) passo colloquially means I don't care :)

@txels
Copy link
Collaborator

txels commented Sep 30, 2012

Nice work. Check the typo(?) and I'll merge.

About feed_data, that is a fair point that someone else raised before. It was a conscious decision to do it like this, but it can be revisited or extended. I just opened an issue as a point for discussion, I'm interested in your feedback (see #3).

The rationale of my initial decision was that if I always unpack data, it would not be possible to write cases where you do want to get tuples fed to your test case (e.g. where you want to test a function that has tuples as parameters).

@santtu
Copy link
Contributor Author

santtu commented Sep 30, 2012

Unintentional. Since the func wasn't really run at all, it didn't show up :-)

txels added a commit that referenced this pull request Oct 3, 2012
Simple enhancement to @DDT decorator to make it possible to provide user-friendly test method names
@txels txels merged commit 0caeb08 into datadriventests:master Oct 3, 2012
@txels
Copy link
Collaborator

txels commented Oct 3, 2012

Merged, sorry about the delay. Thanks!

@santtu
Copy link
Contributor Author

santtu commented Oct 3, 2012

Thanks! When are you planning to update pypi? I have a custom sdist in our build deps I'd like to get rid of :-)

@txels
Copy link
Collaborator

txels commented Oct 3, 2012

There you are, uploaded as 0.2.0.
http://pypi.python.org/pypi/ddt/0.2.0

@santtu
Copy link
Contributor Author

santtu commented Oct 5, 2012

Thanks!

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.

None yet

2 participants