question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically create or add a test to each test suite?

See original GitHub issue

If 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:closed
  • Created 4 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Zac-HDcommented, May 24, 2020

Closing this as an inactive question - hopefully fixtures are working for you 🙂

1reaction
SalmonModecommented, Apr 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found