-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
How to pass a variable from a test to another test #3403
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
Comments
GitMate.io thinks possibly related issues are #2472 (Passing global variable from test function), #3118 (How can I use global variables through tests?), #1694 (Add possibility to pass parameter to the fixture from another fixture), #288 (Pass test result to finalizer for cleaning up debug data), and #153 (test intents). |
Your first 'test' doesn't sound like a test. Does it include any Instead, you can make it a helper method to compute the value you need for your second test, and call that helper method in your second test. Just take of the |
@rachel1792 |
@zzyGit that's not possible without some ugly hack, but unittests are supposed to be idempotent and independent from each other. You should be able to run tests in any other. But @rachel1792's advice is sound, why don't you create a fixture or method which creates the id for you? If the fixture fails for any reason, you will still get an error. Another strategy is using something like: @pytest.fixture
def item():
return Item()
def test_item_created(item):
# ensure item was created successfully
assert item.value == 'something expected'
def test_edit_item(item):
# ensure item is edited successfully
item.edit() |
Closing as this has not seen activity in awhile. |
test_mytest.py:
You can pass dictionaries and lists and anything you feel like. If you require persistence (want the values to be kept from one run to another you can write them in a json file or use the cache option) |
I write a test class, it has two test methods. What I want to do is, at the first test I'd like to get some result and assign to a variable; and at the second test I want to do some test depend on this variable. What's the best way to do this? Currently, I use a "global", and I know I can put these two tests into a same method. But I look forward a better solution.
Thanks for submitting an issue!
Here's a quick checklist in what to include:
pip list
of the virtual environment you are usingThe text was updated successfully, but these errors were encountered: