Comments (9)
I think as it is 2018 and whoever is using the lib now is probably using the newer approach anyway. I'm closing this for now.
from ddt.
Thanks for pointing this out. I didn't realise that was breaking existing behaviour.
I will see how to deal with that. In the meantime, pin your dependency to 1.0.0 if that gets you going, as I'm not sure when I can get some time to revert this/sort this out.
from ddt.
I've pinned it for now, so that should be enough to keep things rolling.
Thanks @txels !
from ddt.
What's the status of this?
from ddt.
@pradyunsg nothing has been done on this yet. Do you want to take a look?
from ddt.
AFAICT, this behavior shouldn't have changed in a patch-version bump. That was a bad mistake.
Since then, another minor version bump has occurred. I recommend the OP to port their tests now, since it's been a while since this change happened. Currently, some people might be using the newer versions (1.0.1+) and it won't be nice to suddenly break their code, intentionally.
It might be easy to write a decorator that handles both cases seamlessly for OP, if the expected number of arguments is 1 then pass a dictionary, if it's more, pass them as keyword arguments.
PS: I am indeed working on parts of this project. Something along the lines of #29, with some other ideas I have in my head. Once that's done, I would like to see all those changes come out as ddt 2.0.0.
I just wrote this decorator... It should work with Py2/3. It's untested though. You can possibly remove the conditionals in the start of the function if you are going to selectively apply only on your ddt
test functions using the old format. Actually, that makes more sense. Because then you would clearly mark which test would need updating.
def adapt_if_needed(func):
""" Adapt functions expecting ddt's old argument format to run with the newer one.
"""
argspec = inspect.getargspec(func)
# If it catches variable arguments, it's probably fine to ignore it
if argspec.varargs is not None or argspec.keywords is not None:
return func
# Count required arguments
required_args = len(argspec.args)
if argspec.defaults:
required_args -= len(argspec.defaults)
# If it takes more than one argument, it's probably fine.
if required_args > 1:
return func
# adapt for older version.
@functools.wraps(func)
def wrapper(**kwargs):
func(kwargs)
return wrapper
from ddt.
In all honesty, looking at PR #22 which is what seems to have caused this issue I would really suggest outright reverting #22 and then just telling people to break down the dictionary themselves. There's nothing stopping them from using a dictionary to manage how many entries they have and splitting it out doesn't really add much code to test.
Though if they really want to keep PR #22's functionality, perhaps it shouldn't be part of unpack
but it's own unpack_dict
to make that kind of functionality explicit.
@pradyunsg sorry...I'm not really seeing benefit to your proposed migration as it seems lacking in matching up arguments especially due to the assumption that a test that previously worked (as @Kuwagata exemplified) would only have 1 parameter, and thinking it through it would seem to me at least not an easy problem to try to determine how many parameters should be able to be matched up. So making the dict unpacking done via its own specific decorator would seem to be the most logical path. Anyone that has come to rely on the new methodology should be able to migrate easily to using a new decorator, which is what you're asking people that have been using the old methodology to do any way. And my guess is that people using the new method are probably fewer in number than people using the old method.
from ddt.
That sounds good too! Having a special decorator for dictionaries sounds like a nice idea. I would like a release period with the addition of the new decorator and a clear warning that the behavior shall change in the next minor version bump.
from ddt.
Bump. Could @txels make this change?
from ddt.
Related Issues (20)
- Add @named_data to give tests meaningful names. HOT 1
- Consider dropping support for all EOL versions Python 2.7 - 3.6 HOT 1
- How to import `named_data`? HOT 1
- Allow `named_data` to take tuples (any `collections.Sequence`)
- Async tests no longer work on python 3.11
- sdist is missing `tox.ini` HOT 6
- 1.7.0: `flake8` reports `pycodestyle` errors HOT 5
- 1.7.0: Has Python 2.7 classifiers but is Python 3+ only. HOT 2
- ddt interaction with setUp and tearDown HOT 2
- Django runserver finds that @file_data has loaded the data and cannot be changed[Help me] HOT 1
- Test Case Ordinal Numbering zero-pads poorly HOT 1
- Index only test names HOT 1
- New release causes error on import HOT 4
- 1.4.1: test suite is failing HOT 2
- Cleanup
- Docs → Example Usage: contents of example data files not shown? HOT 1
- (DDT+Excel+Unittest)How to control the execution of each test case HOT 2
- Test failure with PyYAML 5.4.1 HOT 4
- Signature change of `ddt.idata` in 1.4.3 breaks downstream uses
- @ifile_data - an iterable @file_data decorator HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ddt.