pytest-dev / pytest-dev/pytest-flask

Getting 'Not Found' across all routes

Open
#190 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
499
Forks
93
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
Hello, I'm trying to run pytest-flask's live server in conjunction with selenium, but every one of my registered routes return a 404 status.
Both my app fixture and the live_server's app are the same (app == live_server.appreturns True, but I haven't checked out if they're the exact same object), and both app objects return the expected routes when calling app.url_map

It not only happens in testing: running the suite via a debugger and stopping the execution just before it fails, and visiting the app's routes in another tab or browser results in the same 404 status responses.

To Reproduce
I have the project open and available in github here, in the tests/login_example branch. Just start a virtual environment, install the requirements and run the following test:

pytest src/tests/system/guest/test_login.py

Expected behavior
The test passes.

Screenshots
Checking url_map in the debugger:
Screenshot from 2024-03-29 12-02-06

Firefox showing the error:

Screenshot from 2024-03-29 12-02-26

Environment (please complete the following information):

  • OS: ArchLinux with the Linux 6.8.2 kernel
  • Python Version: 3.11.8
  • pytest-flask version: 1.3.0

Additional context
The test proper:

@pytest.mark.usefixtures('live_server')
class TestLogin(TestSystemBase):
    def test_correct_login(db, driver, live_server):
        driver.get(f"http://localhost:8888{url_for('sessions_controller.new')}")
        assert 'Login' in driver.page_source

My app fixture:

@pytest.fixture(scope='session')
def app():
    app = Flask(__name__)
    app.config['TESTING'] = True
    initializer.init_app(app)
    app.config['SECRET_KEY'] = secrets.token_hex(32)

    with app.app_context():
        yield app

    clear_data(app)

My selenium driver fixture:

@pytest.fixture
def driver():
    options = webdriver.FirefoxOptions()
    #options.add_argument('-headless')
    driver = webdriver.Firefox(options=options)

    yield driver

    driver.close()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run pytest src/tests/system/guest/test_login.py from the linked tests/login_example branch, then inspect the app, live_server, and Selenium driver fixtures shown in the issue. Compare the registered routes in app.url_map with the URLs requested by the test; done means the login route and the test no longer return 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.