Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Tests should export logs in order to improve pipeline integration #222

@CarlosSMA

Description

@CarlosSMA

Problem

I've cloned this repo and am using it in GitLab due to its CI/CD options (clone: https://gitlab.com/CarlosSMA/flask-base).

While doing the process, I've noticed that the tests done in the manage.py file don't export artifact logs in JUnit, and thus the GitLab pipeline can't show what tests were made, and their respective status and duration.

For now, I've implemented the xmlrunner lib in the test() function, however this doesn't seem to be the best solution, and I'd like to avoid using news libs.

Temporary fix

The following code is available on the feat-tests branch:

  • requirements.txt
[...]
urllib3==1.25.8
webassets==0.12.1
Werkzeug==0.15.5
WTForms==2.2.1
xmlrunner==1.7.7
  • manage.py
@manager.command
def test():
    """Run the unit tests."""
    import unittest
    import xmlrunner
    
    test_results = xmlrunner.XMLTestRunner(output="tests-reports", outsuffix='log',).run(unittest.TestLoader().discover("tests"))
  • .gitlab-ci.yml
[...]
job_test:
  stage: test
  tags:
  - test
  script:
  - python3 manage.py test
  artifacts:
    when: always
    reports:
      junit:
      - tests-reports/TEST-test_basics.BasicsTestCase-log.xml
      - tests-reports/TEST-test_user_model.UserModelTestCase-log.xml

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions