Accessing variables defined in pytest
#382
Replies: 1 comment
-
Further down the same StackOverflow issue there is this comment:
and this is closer to my view. It's essentially what I did. (There are, to be clear, two relevant global variables still involved in Both your/SO suggestion and the current solution are intended to achieve the same goal: to make a specified path available for tests. Moreover, the path needs to be obtained "live" on the executing system. My preference is to retain existing behaviour.
|
Beta Was this translation helpful? Give feedback.
-
I was looking into how to access variables defined in
pytest
for some tests I'm writing. I found this answer, which shows what seems to be a concise, builtin way to do so, and started using this:which allows these to be accessed in other test files as
pytest.fixturepath
.However, in looking at some existing tests that I did not write, I saw that something to the same end was already done in at least one place:
Which way should be preferred/retained?
My thought is that we should change to the former, because it lends itself to devs/users being able to quickly see what variables they can access using the
pytest.<variable_name>
syntax, rather than needing to search for them1, and it is a bit more concise.Are there reasons why maintaining the latter would be better, aside from the need to change some existing code?
Footnotes
If I hadn't happened to be looking for an example of something else, I still wouldn't know the latter example was in
conftest.py
. ↩Beta Was this translation helpful? Give feedback.
All reactions