Dynamically create or add a test to each test suite?
See original GitHub issueIf I have test, which I would like perform automatically after each test suite/file. In Python unittest I can do something like this:
# base.py file
class Base(unittest.TestCase):
def test_999(self):
assert check_crash()
# my_test.py file
class TestClass(Base):
def test_01(self):
assert do_something()
def test_02(self):
assert other_thing()
And when writing new test suite, only thing to remember, is that one needs to inherit Base
and test_999
is automatically executed.
But is there way to same thing pytest? So that this:
def test_01():
assert do_something()
def test_02():
assert other_thing()
Would look like this during execution time and in some automatic way?
def test_01():
assert do_something()
def test_02():
assert other_thing()
def test_999():
assert check_crash()
I know that I can workaround the problem by writing plugin and doing this checkup after the all test have been executed. But then it would not be a test, it would be some post action that would fail and it would not be clear what and why it did fail (example xunit output would show that all test did pass.)
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Create dynamic test suite at runtime
A dynamic test suite is a test suite with multiple test cases added via a search query. You can dynamically add additional test...
Read more >How do I Dynamically create a Test Suite in JUnit 4?
To create a dynamic test suite, you need to use the @RunWith annotation. There are two common ways to use it: @RunWith(Suite.class).
Read more >Guide to Dynamic Tests in Junit 5
Learn about dynamic tests introduced in JUnit 5 - a new programming model that supports full test lifecycle.
Read more >Dynamically create test cases with Robot Framework - gerg.dev
With them you could simply have dummy tests that act as markers/templates indicating which suites should be processed. The modifier could then ...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
With its default “BDD”-style interface, Mocha provides the hooks before() , after() , beforeEach() , and afterEach() . These should be used to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing this as an inactive question - hopefully fixtures are working for you 🙂
Exactly. That’s what makes pytest’s fixture system so incredibly powerful.
Let me know if you hit any snags or have any questions about how they work, or if you hit any problems with how to structure them, and I’ll be more than happy to help out.