Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

I can't use the conftest file feature of pytest properly #1345

Answered by mdmintz
HellShuro asked this question in Q&A
Discussion options

My ConfTest file:
image

Here's my test_login file:
image

When I run test_login.py, the inside self automatically creates a new browser window, instead of using the browser window generated by the confTest method

Conftest. py is executed before PyTest has another test item, so you can write some precursors.

What do I have to do to make conftest.py work properly? I have tried using methods like sb.click() that do not create new Windows without using BaseCase. But there is no code completion function in the writing process, which is very inconvenient

What should I do

You must be logged in to vote

Hi @HellShuro,
For the code auto-completion part, you'll need to use BaseCase inheritance, as most code editors will not be able to parse the methods from the pytest sb fixture.
For all standard SeleniumBase tests, the browser is spun up automatically at the start of every test, and then spun down automatically at the end of it. It replaces the need for having to use a conftest.py file to do that. If you need more driver control, you can use the example from https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_override_driver.py for overriding the driver as needed. You can also override the setUp() and tearDown() methods from tests that inherit BaseCase (see https://gith...

Replies: 1 comment 2 replies

Comment options

Hi @HellShuro,
For the code auto-completion part, you'll need to use BaseCase inheritance, as most code editors will not be able to parse the methods from the pytest sb fixture.
For all standard SeleniumBase tests, the browser is spun up automatically at the start of every test, and then spun down automatically at the end of it. It replaces the need for having to use a conftest.py file to do that. If you need more driver control, you can use the example from https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_override_driver.py for overriding the driver as needed. You can also override the setUp() and tearDown() methods from tests that inherit BaseCase (see https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py for more info).

You must be logged in to vote
2 replies
Comment options

But I need to configure different initial actions for different files to be run, for example, for a.py, b.py I need to open Google.com first, for c.py, d.py I need to open YouTube.com, if each one is written in the header of the file then I need to write a lot of duplicate code, well, it doesn't look concise enough. Especially because I want each function to run independently, which means I need to write a self.open(url) in each function, which looks dumb.
I've been thinking about modifying the driver, and setUP, tearDown for a long time, and I still don't have a clue. Can you please provide some more detailed ideas?

Translated with www.DeepL.com/Translator (free version)

Comment options

I gave up and am going to use an override of the setUp method to achieve the effect.

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /