Running Tox Tests take a long time in VSCode DevContainer

Newby to HA Development… Wondering if I am doing something wrong here…

I have setup a Code Dev Container (MacOSX, Docker) and went through the long process of setting uop the container… install dependencies etc…

Now I just want to run a couple of tests inside the container as I am developing, and run the following command from the terminal:

tox -e py36 -- tests/components/template/test_cover.py

This then takes over 8 minutes to run, each and every time… It seem like every time it builds the .tox\dist\homeassistant-0.98.0.dev0.zip file (takes a while) and then runs throuh:

py36 inst-nodeps: /workspaces/home-assistant/.tox/.tmp/package/2/homeassistant-0.98.0.dev0.zip
py36 installed: <redacted>
py36 run-test-pre: PYTHONHASHSEED='1246295556'
py36 run-test: commands[0] | pytest --timeout=9 --durations=10 -qq -o console_output_style=count -p no:sugar tests/components/template/test_cover.py

here is the time is takes to run:

real    8m45.841s
user    0m52.990s
sys     0m44.510s

So am I doing it wrong?

Thanks for any help.

G./

OK. I worked it out… seems that the tox command is only really for preparing a release.

You can run the specific test directly using:

pytest --timeout=9 --durations=10 -qq -o console_output_style=count -p no:sugar  tests/components/template/test_cover.py 

Yes I discovered the same thing. With VSC container we have already an autonomous container to run tests. Using tox is like creating a container in a container… Useless :wink:

I have other issues link to container: with git commands which are very long to return results. Do you notice it too?

hey @oncleben31,

Yes I do notice that. Especially f you run tox… while it builds the ZIP file (outside the .tox) directory, git goes in meltdown (over 5K changes - ‘some git features will be disabled’). And checkins take a while too as it runs black as a pre-commit hook, which sees to run slow across the dev-container bridge.

Also if I look in the git log I see a lot of this:

Failed to watch ref '/workspaces/home-assistant/.git/refs/remotes/origin/dev', is most likely packed.
Error: ENOENT: no such file or directory, watch '/workspaces/home-assistant/.git/refs/remotes/origin/dev'
	at FSWatcher.start (internal/fs/watchers.js:164:26)
	at Object.watch (fs.js:1232:11)
	at Object.t.watch (/root/.vscode-server/bin/036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8/extensions/git/dist/main.js:1:6857)
	at E.updateTransientWatchers (/root/.vscode-server/bin/036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8/extensions/git/dist/main.js:1:97370)
	at u.fire (/root/.vscode-server/bin/036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8/out/vs/server/remoteExtensionHostProcess.js:50:227)
	at T.updateModelState (/root/.vscode-server/bin/036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8/extensions/git/dist/main.js:1:114750)
	at process._tickCallback (internal/process/next_tick.js:68:7)

Not sure what the problem is there, because if I run git remote --verbose outside the container, I get a correct response:

➜  home-assistant git:(dev) ✗ git remote --verbose
origin	[email protected]:xxxxp/home-assistant.git (fetch)
origin	[email protected]:xxxx/home-assistant.git (push)

Thought it could be mismatched versions of git, but when I check the versions they are compatible:

dev-container git: 2.22.1
local git: 2.22.0 

Do you get that too?

I don’t see errors like you and don’t have the same git version. Both are 2.20.1.
And I’ve uninstalled pre-commit to accelerate my dev.

Hey @oncleben31,

I managed to get all my dev work done in the VSCode Dev Container… I did run test manually in the console using the pytest ... command above (and variants)… and checking in using the pre-commit hook … soooo slow!!

Now I am ready to create a PR but I have to run tox before I can submit it… So I killed VSCode and started a terminal session to the docker container using:

docker exec -it :container_id bash

where :container_id is the name of your running container (use the docker ps command to list all running containers. The :container_id is at the end of the line)…

I then changed to the /workplaces/home-assistant directory and ran tox… still too a long time, but was not overburdened with VSCode constantly polling git for changes…

Ran smoother with fewer failing tests… I still have 4 failing tests that are not related to my changes!!!

Is docker really needed to use tox?

I’m trying to follow the instructions here:

but docker seems to be one of many methods, it may be worth try the non-docker method

I am developing on Mac hat is supplied by my employer, so don’t want to pollute it with all the dependencies (I know… virualenv and all that)… so that’s why I prefer to use docker and the code/dev-container integration makes it work pretty well (except the git sync stuff that is a bit slow, especially during tox builds)…

So that’s why I docker it.