Comments (6)
it fails only when my custom function is raising an exception which is catched in the except block.
from python-pytest-steps.
Thanks @alexzanderr for posting this issue.
The problem is that when you catch the exception in the first step, you do not perform the other two steps. In other words, in your function there are not always three"yield" statements reached.
Why do you actually try/catch the exception in the first step ? You should only do this if this exception is normal. Otherwise, simply let pytest fail :)
If the exception is normal and it is legitimate to catch it, then you should write two other steps in the catch branch. Each step should end with "yield".
from python-pytest-steps.
The problem is that when you catch the exception in the first step, you do not perform the other two steps. In other words, in your function there are not always three"yield" statements reached.
yes i know, that.
Why do you actually try/catch the exception in the first step ? You should only do this if this exception is normal. Otherwise, simply let pytest fail :)
im doing that because im making sure that my function is raising the correct type of exception based on the wrong type params or wrong values of params that it got.
from python-pytest-steps.
You might be interested in using with pytest.raises
to actually perform such exception raising checks in a "pytest way".
Anyway whatever you decide, the solution is still very easy: make sure that you have three steps in all branches of your code, and that will work. For example:
try:
# we know that this raises some errors
# when the @real_number its not valid
result = fixed_set_precision_str(real_number, precision)
print(result)
except TypeError as error:
print(error)
# step 1
yield
# step 2
yield
# step 3
yield
except ValueError as error:
print(error)
# step 1
yield
# step 2
yield
# step 3
yield
else:
_decimals = get_total_decimals(result)
# step 1
# correct number of decimals ?
assert _decimals == precision
yield
# step 2
# is type str ?
assert isinstance(result, str)
yield
# step 3
# result == expected ?
assert result == expected_result
yield
Indeed pytest does not allow for dynamic modification of the number of tests. So if you declare three steps then there must be three tests, and the only way pytest-steps is able to know what you put inside is to look at the yield statements.
from python-pytest-steps.
yes, indeed, the solution is to repeat fake yields inside the except block.
# step 1
yield
# step 2
yield
# step 3
yield
thanks a lot for support!
from python-pytest-steps.
You're welcome!
from python-pytest-steps.
Related Issues (20)
- `@cross_steps_fixture` does not wait for the last step to perform teardown
- `pytest_harvest` should not be mandatory for install
- Plugin fails to be detected when pytest-harvest is not present
- When calling a decorated test function manually, the test step list is not taken into account HOT 1
- If a step that is not the first is selected by a '-k' keyword selection in pytest, no error is raised and the wrong step is run
- pytest-steps is not compatible with async functions (pytest.mark.asyncio) HOT 4
- Protect against python 2 unicode literals
- Replace `@with_signature(new_sig)` with stub files (`*.pyi`)
- Python 3.8 incompatibility: DeprecationWarning: collections.abc HOT 1
- Improve packaging
- TypeError: test_suite() missing 2 required positional arguments: '________step_name_' and 'request' HOT 15
- TypeError: Unable to hash test parameter '...'. Hashable parameters are required to use steps reliably. HOT 1
- Pytest marks on generator test step? HOT 2
- order inverted HOT 3
- pandas deprecation warning in steps_pytest_harvest_utils.py HOT 7
- Migrate project template to new one using github actions
- pytest-harvest + pytest-steps: results_bag fixture is cross-step, how to get per-step? HOT 5
- 1.8.0: pytest is failing HOT 13
- yield <step-name> does not work without extra yield at the top of the test case HOT 2
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 python-pytest-steps.