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

Set environment variable when coverage run is executed #771

Closed
s0undt3ch opened this issue Jan 30, 2019 · 6 comments
Closed

Set environment variable when coverage run is executed #771

s0undt3ch opened this issue Jan 30, 2019 · 6 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@s0undt3ch
Copy link

Is your feature request related to a problem? Please describe.
I'd like my code to know that coverage is "calling the shots", ie, coverage run -m <blah>

Describe the solution you'd like
My solution would be to set an environment variable when coverage run -m <blah> is executed, that way, my <blah> "program" knows how its being executed.
This allows my code to also inject in the environment, at runtime, for example COVERAGE_PROCESS_START, and also inject the path to a custom directory containing siteconfig.py so that coverage tracks my subprocesses.

Describe alternatives you've considered
I tried setting up my tox file to set the COVERAGE_PROCESS_START variable, however, that solution does not work well for both *Nix and Windows.

00:28:00        Failed to import the site module
00:28:00        Traceback (most recent call last):
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 791, in <module>
00:28:00            main()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 781, in main
00:28:00            execsitecustomize()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 553, in execsitecustomize
00:28:00            import sitecustomize
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\tests\support\coverage\sitecustomize.py", line 9, in <module>
00:28:00            coverage.process_startup()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\control.py", line 1287, in process_startup
00:28:00            cov = Coverage(config_file=cps)
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\control.py", line 149, in __init__
00:28:00            concurrency=concurrency,
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\config.py", line 467, in read_coverage_config
00:28:00            raise CoverageException("Couldn't read '%s' as a config file" % fname)
00:28:00        coverage.misc.CoverageException: Couldn't read 'C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing/.coveragerc' as a config file

Maybe a os.path.normpath() would fix the above exception, but I'd still like to know that coverage run was used...

@s0undt3ch s0undt3ch added the enhancement New feature or request label Jan 30, 2019
@nedbat
Copy link
Owner

nedbat commented Jan 30, 2019

Hmm, when I read the title, I thought, "You should have whatever is running coverage also set the environment variables." Maybe we can debug what went wrong when you tried to have tox set the variables? Can you share the details?

@s0undt3ch
Copy link
Author

The tox.ini is quite complex, though, the important bit is this.

Our CI call was:

00:24:06        Running Command: cmd.exe /c "tox -c %TEMP%\kitchen/testing/tox.ini -e py3-pytest-coverage -- --output-columns=120 --sysinfo --junitxml=%TEMP%\kitchen/testing/artifacts/xml-unittests-output/test-results.xml --names-file=%TEMP%\kitchen\testing\tests\whitelist.txt --transport=zeromq -v --run-destructive --ssh-tests  -sv -ra --log-cli-level=INFO --sys-stats   2>&1" 2>&1
00:24:08        py3-pytest-coverage create: C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage
00:24:28        py3-pytest-coverage installdeps: -UrC:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing/requirements/tests.txt
00:27:59        ERROR: invocation failed (exit code 1), logfile: C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\log\py3-pytest-coverage-2.log
00:27:59        ERROR: actionid: py3-pytest-coverage
00:27:59        msg: envreport
00:27:59        cmdargs: "'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\kitchen\\testing\\.tox\\py3-pytest-coverage\\Scripts\\python.EXE' -m pip freeze"
00:28:00        
00:28:00        Failed to import the site module
00:28:00        Traceback (most recent call last):
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 791, in <module>
00:28:00            main()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 781, in main
00:28:00            execsitecustomize()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site.py", line 553, in execsitecustomize
00:28:00            import sitecustomize
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\tests\support\coverage\sitecustomize.py", line 9, in <module>
00:28:00            coverage.process_startup()
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\control.py", line 1287, in process_startup
00:28:00            cov = Coverage(config_file=cps)
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\control.py", line 149, in __init__
00:28:00            concurrency=concurrency,
00:28:00          File "C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\lib\site-packages\coverage\config.py", line 467, in read_coverage_config
00:28:00            raise CoverageException("Couldn't read '%s' as a config file" % fname)
00:28:00        coverage.misc.CoverageException: Couldn't read 'C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing/.coveragerc' as a config file
00:28:00        
00:28:00        Traceback (most recent call last):
00:28:00          File "c:\python35\lib\runpy.py", line 193, in _run_module_as_main
00:28:00            "__main__", mod_spec)
00:28:00          File "c:\python35\lib\runpy.py", line 85, in _run_code
00:28:00            exec(code, run_globals)
00:28:00          File "C:\Python35\Scripts\tox.exe\__main__.py", line 9, in <module>
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 47, in cmdline
00:28:00            main(args)
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 54, in main
00:28:00            retcode = build_session(config).runcommand()
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 467, in runcommand
00:28:00            return self.subcommand_test()
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 590, in subcommand_test
00:28:00            self.run_sequential()
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 608, in run_sequential
00:28:00            self.runenvreport(venv)
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 715, in runenvreport
00:28:00            packages = self.hook.tox_runenvreport(venv=venv, action=action)
00:28:00          File "c:\python35\lib\site-packages\pluggy\hooks.py", line 284, in __call__
00:28:00            return self._hookexec(self, self.get_hookimpls(), kwargs)
00:28:00          File "c:\python35\lib\site-packages\pluggy\manager.py", line 68, in _hookexec
00:28:00            return self._inner_hookexec(hook, methods, kwargs)
00:28:00          File "c:\python35\lib\site-packages\pluggy\manager.py", line 62, in <lambda>
00:28:00            firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
00:28:00          File "c:\python35\lib\site-packages\pluggy\callers.py", line 208, in _multicall
00:28:00            return outcome.get_result()
00:28:00          File "c:\python35\lib\site-packages\pluggy\callers.py", line 80, in get_result
00:28:00            raise ex[1].with_traceback(ex[2])
00:28:00          File "c:\python35\lib\site-packages\pluggy\callers.py", line 187, in _multicall
00:28:00            res = hook_impl.function(*args)
00:28:00          File "c:\python35\lib\site-packages\tox\venv.py", line 631, in tox_runenvreport
00:28:00            output = venv._pcall(args, cwd=venv.envconfig.config.toxinidir, action=action)
00:28:00          File "c:\python35\lib\site-packages\tox\venv.py", line 527, in _pcall
00:28:00            args, cwd=cwd, env=env, redirect=redirect, ignore_ret=ignore_ret, returnout=returnout
00:28:00          File "c:\python35\lib\site-packages\tox\session.py", line 251, in popen
00:28:00            raise tox.exception.InvocationError("{} (see {})".format(invoked, outpath), ret)
00:28:00        tox.exception.InvocationError: InvocationError for command C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\Scripts\python.EXE -m pip freeze (see C:\Users\ADMINI~1\AppData\Local\Temp\kitchen\testing\.tox\py3-pytest-coverage\log\py3-pytest-coverage-2.log) (exited with code 1)
00:28:00        Verify command failed :: WinRM exited (1) for command: [ cmd.exe /c "tox -c %TEMP%\kitchen/testing/tox.ini -e py3-pytest-coverage -- --output-columns=120 --sysinfo --junitxml=%TEMP%\kitchen/testing/artifacts/xml-unittests-output/test-results.xml --names-file=%TEMP%\kitchen\testing\tests\whitelist.txt --transport=zeromq -v --run-destructive --ssh-tests  -sv -ra --log-cli-level=INFO --sys-stats   2>&1" 2>&1]

If it matters, this is our sitecustomize.py

@s0undt3ch
Copy link
Author

tox==3.7.0
Latest released coverage library.
Our CI process on windows does not output the tox installed dependencies :/

@nedbat
Copy link
Owner

nedbat commented May 17, 2019

Is this still an issue I can help with?

@s0undt3ch
Copy link
Author

No @nedbat, we can close it.
We switched to nox where we have more leverage.

Thanks for coverage!

@nedbat
Copy link
Owner

nedbat commented Nov 15, 2021

This was implemented in #553.

@nedbat nedbat added the duplicate This issue or pull request already exists label Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants