Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

El test del ejercicio 09.1 del prework de DS no pasa si uso funciones #1315

Closed
marcogonzalo opened this issue Feb 15, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working 🔥 urgent ⭐️ P1

Comments

@marcogonzalo
Copy link

ejercicio 09.1 pythonlist:
09.1 Minimum integer:

El test falla si se hace como funciones, pero no si se hace imperativo. Se hizo con funciones porque en los anteriores ya se venía pidiendo hacer funciones, por lo que creo que es importante permitirlo

@UmiKami
Copy link

UmiKami commented Mar 23, 2023

Cambié el test y las instrucciones para que se use una funcion la cual retorna el valor minimo de una lista.

@UmiKami
Copy link

UmiKami commented Mar 23, 2023

@UmiKami
Copy link

UmiKami commented Mar 23, 2023

New test case:

@pytest.mark.it("The function should print the minimum number from my_list")
def test_printed_output(capsys, app):
    def minInteger_wrapper(my_list):
        result = app.minInteger(my_list)
        print(result)
        return result

    original_minInteger = app.minInteger
    app.minInteger = minInteger_wrapper

    exec(open(app.__file__).read())
    captured = capsys.readouterr()

    app.minInteger = original_minInteger

    assert int(captured.out.strip()) == min(app.my_list)

Explanation:

  1. It defines a minInteger_wrapper function that calls the original minInteger function, prints the result, and returns it.
  2. It temporarily replaces the minInteger function in the app module with the wrapper function.
  3. It re-executes the app.py file, which now calls the wrapper function instead of the original minInteger function, and thus captures the printed output.
  4. It restores the original minInteger function in the app module.
  5. It checks if the captured output matches the minimum value in my_list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔥 urgent ⭐️ P1
Projects
None yet
Development

No branches or pull requests

3 participants