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

run doesnt maintain state between runs #83

Open
MichaelAquilina opened this issue Aug 15, 2017 · 11 comments
Open

run doesnt maintain state between runs #83

MichaelAquilina opened this issue Aug 15, 2017 · 11 comments

Comments

@MichaelAquilina
Copy link
Contributor

Hopefully this isnt another non-issue, but using run doesnt seem to maintain it's environment between subsequent calls in the same test.

e.g.

@test 'something' {
    echo "hello" > "foo/bar"

    run cd foo
    run cat bar
}

the second run will fail because the cd to foo is not maintained

@molovo
Copy link
Member

molovo commented Aug 15, 2017

Yep, that's intended bahaviour - the run helpers runs the command in a subprocess in isolation, purely so that the $output and $state can be asserted against. To do something like the above, you'd be better off with one of the following options:

# Call the full path firectly
run cat foo/bar

# Or, if the cd is absolutely necessary, run it in the main
# test scope, so that it affects the test process, and is not
# run in an isolated subprocess
cd foo
run cat bar

@MichaelAquilina
Copy link
Contributor Author

MichaelAquilina commented Aug 15, 2017

In my case the second option seems necessary as cd'ing to the directory is part of the test (this is for testing https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv).

However, for some reason the cd fails without any good reason. I am guessing this is more to do with what my plugin is doing than zunit so I feel like I need to dig into this more.

@molovo
Copy link
Member

molovo commented Aug 15, 2017

Is it the master branch which is failing? I spotted this typo in the @setup function if that helps. It's present in all three test files.

I'll download a copy of that repo when I get home and take a look

@MichaelAquilina
Copy link
Contributor Author

MichaelAquilina commented Aug 15, 2017

That should work, It's a zsh shortcut:

$ echo =virtualenvwrapper.sh                
/home/michael/.virtualenvs/zsh-autoswitch-virtualenv/bin/virtualenvwrapper.sh

Its almost equivalent to which

@molovo
Copy link
Member

molovo commented Aug 15, 2017

Oh, nice. I hadn't heard of that before. I figured it was a variable assignment

@molovo
Copy link
Member

molovo commented Aug 17, 2017

I'm getting errors when I'm running the tests that the virtualenvwrapper.sh script can't be found. Am I looking at the wrong branch? (This is on master)

TAP version 13
not ok 1 - Failure: changing to a directory without .venv defaults
  ---
  message: __zunit_test_setup:1: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 2 - Failure: changing to a directory with .venv autoswitches
  ---
  message: __zunit_test_setup:1: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 3 - Failure: chpwd functions are loaded
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 4 - Failure: _check_venv_path with non-existent path
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 5 - Failure: _check_venv_path with no venv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 6 - Failure: _check_venv_path with existing venv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 7 - Failure: _check_venv_path in subdirectory with parent venv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 8 - Failure: rmvenv with no .venv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 9 - Failure: rmvenv with existing .venv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
not ok 10 - Failure: rmvenv with existing .venv with deleted virtualenv
  ---
  message: __zunit_test_setup:2: virtualenvwrapper.sh not found
  severity: fail
  ...
1..10

@MichaelAquilina
Copy link
Contributor Author

Have you installed virtualenvwrapper?

pip install virtualenvwrapper

You will probably need to use sudo to install that (or use a python virtualenv)

@molovo
Copy link
Member

molovo commented Aug 17, 2017

Ah, that would help. Can you tell I'm not a python guy? 😂

@MichaelAquilina
Copy link
Contributor Author

haha no problem! I was away in Germany the past few days so I havent managed to give this a look since we last spoke. Any luck from your side? I will probably try find some time today to try clean this all up

@molovo
Copy link
Member

molovo commented Sep 5, 2017

Sorry, I haven't got anywhere with this. I've had a couple of attempts, but I've had no luck getting virtualenvwrapper itself set up properly in order to run these tests. If you have a Vagrantfile/Dockerfile with an environment where this runs I'd be happy to take another look in that environment.

However, looking at the travis output from the master branch, ZUnit doesn't appear to be doing anything that it's not supposed to. Did the cd failure that you reference above happen in master, or another unpublished branch?

@MichaelAquilina
Copy link
Contributor Author

I need to give the tests for this project a proper look because i noticed quite a few are passing automatically due to the contains bug. So better I gather some more information for you first :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants