Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

450
Views
pytest con Flask no puede localizar el módulo

Estoy aprendiendo Flask siguiendo este tutorial https://flask.palletsprojects.com/en/1.1.x/#user-s-guide pero, cuando intento ejecutar pytest , aparece este error:

 (FlaskVenv) MacBook-Pro-de-Hugo:FlaskProject hugovillalobos$ pytest ImportError while loading conftest '/Users/hugovillalobos/Documents/Code/FlaskProject/tests/conftest.py'. tests/conftest.py:4: in <module> from Flaskr import create_app E ModuleNotFoundError: No module named 'Flaskr'

Este es el módulo que genera el error ( conftest.py ):

 import os import tempfile import pytest from Flaskr import create_app from Flaskr.db import get_db, init_db with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f: _data_sql = f.read().decode('utf8') @pytest.fixture def app(): db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'DATABASE': db_path, }) with app.app_context(): init_db() get_db().executescript(_data_sql) yield app os.close(db_fd) os.unlink(db_path) @pytest.fixture def client(app): return app.test_client() @pytest.fixture def runner(app): return app.test_cli_runner()

Este es el código para dicho módulo como se muestra en el tutorial (la única diferencia es que mi módulo está en mayúsculas):

ingrese la descripción de la imagen aquí

Pensé que podría ser un problema con la ubicación de mis archivos, pero estoy mapeando el diseño del proyecto del tutorial correctamente:

ingrese la descripción de la imagen aquí

No sé lo que me estoy perdiendo.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es posible que deba ejecutar pytest como un módulo en python (que agrega el directorio actual a sys.path). Recuerdo haber tenido una situación similar y esto me lo resolvió:

 python -m pytest -vv

Fuente: https://docs.pytest.org/en/latest/usage.html#calling-pytest-through-python-m-pytest

Puede invocar las pruebas a través del intérprete de Python desde la línea de comando:

python -m pytest [...] Esto es casi equivalente a invocar el script de línea de comando pytest [...] directamente, excepto que llamar a través de python también agregará el directorio actual a sys.path.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!