using pytest fixture and test collection outside of pytest command line #9267
-
Hi, While there is some effort in to support separate test runners such as pytest in cocotb it's not there yet. I've created a method to discover and run pytests but it's fragile and not generic. So I'm asking if there are any specific hooks or features in pytest that may improve this. From my external test runner I can add pytests using the following:
Current solution is based on parsing pytest --collect-only output:
The testlist is used to generate test functions that can be added to the cocotb regression manager:
As I said, this is fragile. The make_fixture() method creates the required fixture from the DUT. The fixtures I support all are known up front and I'm not reusing pytest fixtures - but i'd like to.
As you can see, it would be much more powerful to have pytest handle this.
Could this be done using hooks?
I think I've got some alternatives to try out but would love to hear from the community. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
pytest currently is not designed to be used as a library, so collecting and running tests at best can be a hack, if you don't integrate in the framework as your surrounding use-case is unclear to me (im not familiar with cocotb) i cant give any further input yet |
Beta Was this translation helpful? Give feedback.
-
Hi @movadaml, DIdn't look into the details, but if I were in the same situation I would approach this by calling |
Beta Was this translation helpful? Give feedback.
Hi @movadaml,
DIdn't look into the details, but if I were in the same situation I would approach this by calling
pytest.main(..., plugins=[cocotb_plugin])
, wherecocotb_plugin
is an instance of class which implements some pytest hooks, which are in turn used to communicate back to thecocotb
frame work. This should provide some flexibility plus is the supported way to interact with pytest. Creating the structures and using them directly is not supported, and prone to break between pytest releases.