Comments (22)
sorry, can you please explain more about the issue?
What's your feature file, and the test code?
from pytest-bdd.
Here is my scenario:
Scenario Outline: Creating a user
Given I am logged in as admin
And I select Users and Groups in site setup
When I add user <user>
Then User <user> should be created
Examples:
| user |
| user1 |
| user2 |
Now I don't want the "Given I am logged in as admin" to be executed for each user in list.
I tried to use "Background" but that didn't work either.
Hope I am being clear,
from pytest-bdd.
Well, it's the nature of outline/parametrization:
single test code, multiple TESTS
the whole scenario will be executed, one time for set of parameters
Why would you not want to run Given I am logged in as admin
?
tests should be isolated, and making test setup (given is the setup) each time is a good thing for isolation
from pytest-bdd.
if you use pytest-splinter, for example, it makes sure your browser is clean every test run, so it cleans cookies
from pytest-bdd.
But we also want tests to run in a reasonable amount of time.
What is the mechanism to have some steps run only once but have other steps parameterized?
from pytest-bdd.
browser gives you a fixture with module scope, so that works very well. I can login once and run a whole bunch of things.
from pytest-bdd.
I think this can be done on the python file with @pytest.mark.parameterize.
It would be nice to be able to specify something in the scenario itself to get this behavior.
from pytest-bdd.
well, then you can do this:
@pytest.fixture(scope='session')
def logged_in(browser):
browser.login()
pytest_bdd.given('I am logged in as admin', fixture='logged_in')
this way you'll get what you want
from pytest-bdd.
Thanks. Shall try it now.
from pytest-bdd.
by default, all steps are function-scoped, but that way you can make some given step to have other scope
from pytest-bdd.
probably we should make it a parameter on given step
from pytest-bdd.
I got:
E ScopeMismatchError: You tried to access the 'function' scoped fixture 'browser' with a 'session' scoped request object, involved factories
E test_create_user.py:10: def logged_in(browser)
E ../../../local/lib/python2.7/site-packages/pytest_splinter/plugin.py:359: def browser(request, browser_instance_getter)
from pytest-bdd.
I tried to save an attribute called 'already_logged_in' in browser which I check before logging in.
It is set but the cookie is gone. So it is session scoped (since it had my attribute) but the cookies got lost,
from pytest-bdd.
pytest-splinter says it is session scoped.
from pytest-bdd.
right, pytest-splinter is not ready for such use-case...
please try to change pytest_splinter/plugin.py:browser_instance_getter
it's scope to session
and then declare
@pytest.fixture(scope='session')
def session_browser(browser_instance_getter):
return browser_instance_getter(session_browser)
and then you'd have to use session_browser for all steps of that scenario, otherwise you'll be logged off
from pytest-bdd.
if you'll succeed, i'll make a new release of pytest-splinter which will include such changes
from pytest-bdd.
browser_instance_getter uses fixture tmpdir from pytest which is not session scoped. Should we patch/duplicate?
from pytest-bdd.
ok.. I made a session_tmpdir fixture and everything works.
I still get an error on teardown:
def make_screenshot_on_failure():
if splinter_make_screenshot_on_failure and request.node.splinter_failure:
E AttributeError: 'Session' object has no attribute 'splinter_failure'
/home/suresh/pytest-splinter/pytest_splinter/plugin.py:321: AttributeError
Investigating.
from pytest-bdd.
ok.. will send pull request
from pytest-bdd.
so try pytest-splinter==1.3.4
from pytest-bdd.
pytest-bdd 2.7.1 is out, you can pass scope for given steps now
from pytest-bdd.
Works great. You rock!
from pytest-bdd.
Related Issues (20)
- RFE: is it possible to restart making github releases?🤔 HOT 2
- How to use multiple values for a parameter in Scenario Outline Examples
- Custom hooks HOT 1
- Issue with pytest-bdd Failing to Identify Correct Scenario Path After Folder Name Change HOT 2
- `iterparentnodeids` removed from pytest HOT 1
- Step definition parses wrong parameter from feature file
- Unable to run parallel tests with pytest-xdist - can't serialize <class 'pytest_bdd.parser.Step'> HOT 1
- Pytest emits deprecation warning: "A private pytest class or function was used" HOT 3
- pytest-bdd doesn't support pytest 8.1.0 HOT 5
- Missing git tags for 7.1 and 7.1.1 releases HOT 1
- Python 3.8/pytest 3.0.4/pytest-bdd 3.1.0 crash: TypeError: an integer is required (got type bytes) HOT 2
- Pytest 8.1.1 fixture injection compability HOT 2
- Unable to run pytest-bdd with pytest-xdist, can't serialize <class 'pytest_bdd.parser.Step'> HOT 4
- Does pytest-bdd support pytest-xdist? HOT 2
- Version 7.1.2 no longer provides pytest_bdd.steps.inject_fixture HOT 1
- Issue with existing working automation after python 3.11.1 and pytest-bdd 7.00 upgrade HOT 6
- Re-use of target_fixture not possible anymore HOT 1
- How to apply for function/module/package/session scope to feature HOT 2
- Is there a hook for 'before_feature' in pytest-bdd?
- Multiple step scenarios targeting the same fixture doesn't update the fixture HOT 3
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 pytest-bdd.