0

I am trying to do an automated test.
There should be 21 tests, but github-actions can't find them for some reason. https://github.com/duri0214/portfolio/actions/runs/4215160033/jobs/7316095166#step:3:6 enter image description here

manage.py is under mysite directory, so...
(Below is when I run it on my local PC)

(venv) PS D:\OneDrive\dev\portfolio\mysite> python manage.py test
  Found 21 test(s).
  Creating test database for alias 'default'...
  System check identified no issues (0 silenced).
   :
  self.client.post(reverse('vnm:likes', kwargs={'user_id': 1, 'article_id': 99}), follow=True)
  AssertionError: ObjectDoesNotExist not raised

  ======================================================================
  FAIL: test_post_click_good_button 
  (vietnam_research.tests.test_views.TestView)
  ----------------------------------------------------------------------

  OK

Anyone know a solution? thanks

yoshitaka okada
  • 113
  • 1
  • 12
  • In your workflow (https://github.com/duri0214/portfolio/actions/runs/4215160033/workflow), you're not activating `venv` but locally you are. – Azeem Feb 19 '23 at 13:05
  • thank you. Certainly "venv activate" was none. next research at 'activate'. It is difficult because the directory structure is different from the usual environment ``` - name: Install venv run: | apt -y install python3.8-venv python3 -m venv venv venv/bin/activate ls ``` – yoshitaka okada Feb 19 '23 at 14:44
  • You need to add `sudo` before `apt` here: https://github.com/duri0214/portfolio/actions/runs/4216771566/workflow#L30. Also, you need to move this step before your `pip install -r requirements.txt` step to make it install deps under `venv`. – Azeem Feb 19 '23 at 15:12
  • Azeem san Thank you for taking the consultation. I want to solve this. https://github.com/duri0214/portfolio/actions/runs/4221902706/jobs/7329752733#step:4:29 If you don't have python3.8-venv, you'll get an error, but in my production environment, the installation of venv seems to work as follows (I'm sorry that it's hard to see because you can't do line breaks) ``` ubuntu@ik1-336-28225:~$ sudo apt -y install python3.8-venv : python3.8-venv is already the newest version (3.8.10-0ubuntu1~20.04.6). ``` – yoshitaka okada Feb 20 '23 at 09:28
  • Error: Process completed with exit code 100. still seems to be a permission error – yoshitaka okada Feb 20 '23 at 10:17
  • Please test [this](https://rhysd.github.io/actionlint/#eJyFUM1uwyAMvucp/AIkh95yqrRe+gzTNDmJldCBYdhEi7SHH9Bqh0rTLiD7+wVGTyNcbshrgJdr1wUeO4CYZas3wJSQ541khFePopTeGuzce6LPTKJ/0rpbmKSiU7ZuudNSZjElAvKUWbNxqMWiQUUU5c4ykKVa4aw2sAzFeP4IWc/76YFzq31lUXQOLhSJF+LZkgDyUmOgGkujt9gRvh9DqX/oFvgExsNOvLfjF+zbOEyWh5q/l4ZPwqqLNoJ9xBuT45pwobr9j5ug/ptN5IlVev3SZ4U/xCoNHhlX6uPRXvIDPvKE6Q==) minimal workflow for your use case. – Azeem Feb 20 '23 at 10:29
  • the build is [correct](https://github.com/duri0214/portfolio/actions/runs/4223129557/jobs/7332485465)! :) But I can only find 0 tests ... I am reading the log now – yoshitaka okada Feb 20 '23 at 12:15
  • I never knew there was a playground in "Actions" :) – yoshitaka okada Feb 20 '23 at 12:18
  • That's an online linter, not a playground. You removed `.` from here: https://github.com/duri0214/portfolio/actions/runs/4223129557/workflow#L27. – Azeem Feb 20 '23 at 12:21
  • I added '.' but still Found 0 test(s). I wonder what the other reason is... [this](https://github.com/duri0214/portfolio/actions/runs/4223305832/jobs/7332884769) – yoshitaka okada Feb 20 '23 at 12:27
  • Are you using pytest for writing tests? – Azeem Feb 20 '23 at 12:29
  • Tests are standard django, run via manage.py [test source is here](https://github.com/duri0214/portfolio/tree/master/mysite/vietnam_research/tests) – yoshitaka okada Feb 20 '23 at 12:36
  • Azeem san. I'm sleepy. today is over. thanks a lot. – yoshitaka okada Feb 20 '23 at 13:56
  • Check this [workflow](https://github.com/iamazeem/test/actions/runs/4225152618/workflow#L14-L30) and its respective [run](https://github.com/iamazeem/test/actions/runs/4225152618/jobs/7337044606#step:4:326). Apparently, you did not check out the `__init__.py` files and they are added in your [`.gitignore`](https://github.com/duri0214/portfolio/blob/master/.gitignore#L7). So, you need to check those out to make this work. Also, an additional step i.e. `cd mysite` before running the test command. For DB-based tests, you need to provide the env vars also e.g. via GHA secrets. – Azeem Feb 20 '23 at 16:09
  • Thank you for all your help. Looks like it recognized the test thanks to you. [this](https://github.com/duri0214/portfolio/actions/runs/4231028109/jobs/7349044338#step:4:831) . Various errors started to appear, but I think it's probably because the migration has not been completed. – yoshitaka okada Feb 21 '23 at 09:26
  • I think there was a "solve" button, but I can't find it. . – yoshitaka okada Feb 21 '23 at 09:29
  • You're welcome! I have posted an answer will the relevant details. – Azeem Feb 21 '23 at 09:47

1 Answers1

0

After looking at your repo (https://github.com/duri0214/portfolio) and testing it locally on my side, I found out that __init__.py was missing. Maybe, it was due to the fact that it was added in your .gitignore file which prevented its inclusion in your repo.

Here's the sample workflow that I tested it with:

name: python_test

on: workflow_dispatch

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v3
      with:
        repository: duri0214/portfolio

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.8
        cache: pip

    - name: Set up and run tests
      run: |
        python3 --version
        python3 -m venv venv
        . venv/bin/activate
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        cd mysite
        touch ./vietnam_research/__init__.py
        touch ./vietnam_research/tests/__init__.py
        python manage.py test

You may observe the __init__.py being manually created in the last step.

So, you have to remove __init__.py from your .gitignore file and push those to your repo.

Apart from that, you need to cd mysite first before running the test command. Also, your tests seem to be using database and environment variables to be run successfully. So, you'll have to configure the database (if required) and set the env vars via GitHub secrets accordingly.

Azeem
  • 11,148
  • 4
  • 27
  • 40
  • Azeem san. thanks a lot :) I also understood the importance of `__init__`, which I had previously ruled out as meaningless. – yoshitaka okada Feb 21 '23 at 11:13
  • @yoshitakaokada: You're welcome! :) You might want to go through this [thread](https://stackoverflow.com/questions/2037364/django-test-runner-not-finding-tests). Might be helpful. – Azeem Feb 21 '23 at 11:20